Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7496957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:52:11+00:00 2026-05-29T18:52:11+00:00

I have an issue with my model in EF model first. I have a

  • 0

I have an issue with my model in EF model first. I have a web app, with security layer and entity layer and mvc3 layer. So in each layer I put a instance of my context db (one for each class in the main declaration section). the problem is when y find any user of my db for validate the login process, simple search, not make any changes in entity, is like this:

var usr = db.Usuarios.First(user => user.UserName.Equals(userName));

If I change the password for example in other layer (in my controller user), and the logout an login again, the linq search (see code up) always return the old password. This is for the context db dont dispose and dont go to database for the data, simple load the user for the model.

So, how I can force the model to refresh the data from the database?
I try, put lazy load in false but not work.

db.Configuration.LazyLoadingEnabled = false;

partial work if I decalre a instance of my context in the metod to validate passwork and dispose this instance, but I think it is the best practice.

like that:

    public static bool ValidateUser(string userName, string password)
    {
        if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
        {
            var dbtmp = new ConorContainer();

            var usr = dbtmp.Usuarios.First(user => user.UserName.Equals(userName));
            if (usr != null)
            {
                var passDescrypt = Decript(usr.Password);
                dbtmp.Dispose();
                return passDescrypt.Equals(password);
            }
            return false;
        }
        return false;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T18:52:19+00:00Added an answer on May 29, 2026 at 6:52 pm

    You have to decide the lifetime of the context in each case. It is preferred to use short lived contexts in web applications specially in static methods.

    Your method can be improved by employing the using block that will call the Dispose method when going out of scope.

    public static bool ValidateUser(string userName, string password)
    {
        if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
        {
            using(var dbtmp = new ConorContainer())
            {
    
                var usr = dbtmp.Usuarios.First(user => user.UserName.Equals(userName));
                if (usr != null)
                {
                     var passDescrypt = Decript(usr.Password);
                     return passDescrypt.Equals(password);
                }
            }
    
            return false;
        }
    
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a code first model: namespace InternetComicsDatabase.Models { public class Issue { [Key]
We have an issue on our page whereby the first time a button posts
I have an issue about Entity Framework 4 CTP 5, which I realize LINQ
I have a 'tabbed' style web page where once the page loads each tab
I have a friend that is moving a web application from one server over
I have a small web app running on AppEngine and have all my URL
We have a simple domain model: Contact, TelephoneNumber and ContactRepository. Contact is entity, it
I have a simple Web App that receives data via a web service and
I'm building a web-application with MS MVC 3 and have run into an issue,
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.