I am a bit confused and wanted to know technically what exactly happens when i call each of these command, also which is preferable over another.
My scenario is in desktop application, where there is a LoginForm, in which:
- User Logs In by giving username, password.
- I changed password directly in the database against current user.
- User Logs out.
- User Logs in again by giving username and new password but context is still holding old password.
PROBLEM STATEMENT: HOW TO GET REFRESH DATA, BELOW IS MY CODE SNIPPET
public partial class LoginForm : Form
{
EntitiesModel _context = null;
public LoginForm()
{
InitializeComponent();
}
private void LoginForm_Load(object sender, EventArgs e)
{
_context = new EntitiesModel(Global.ConnectionString);
}
private void btnLogin_Click(object sender, EventArgs e)
{
USER user = _context.USERs.FirstOrDefault(u => u.USERNAME == txtUsername.Text.Trim() && u.PASSWORD == txtPassword.Text.Trim());
// after authentication show main menu etc
}
private void btnLogout_Click(object sender, EventArgs e)
{
//option 1: i dispose off current context here and create new context each time login button is clicked, so that context fetches latest password from database
if (_context != null)
_context.Dispose();
//option 2: i only release all entities from current context cache and use the same context each time login button is clicked rather creating new context
_context.cache.ReleaseAll();
}
}