title: DbContext usage and property values
body: <p>First off, let's start by saying I'm a rookie.  That being said,  I am building a web app in C# using MVC3 w/ EF4.3.1 using a db first approach. During the log on process, I want to set some session variables to be used throughout the app.  </p>
  
  <p>My issue is that I am not sure how to go about reading the values into the session variables.  Below is the code currently in the AccountController.cs:</p>
  
  <pre><code>[HttpPost]
  public ActionResult LogOn(LogOnModel model, string returnUrl)
  {
      if (ModelState.IsValid)
      {
          if (Membership.ValidateUser(model.UserName, model.Password))
          {
              FormsAuthentication.SetAuthCookie(model.UserName, 
                                                model.RememberMe);
              if (Url.IsLocalUrl(returnUrl) 
                  &amp;&amp; returnUrl.Length &gt; 1 
                  &amp;&amp; returnUrl.StartsWith("/")
                  &amp;&amp; !returnUrl.StartsWith("//") 
                  &amp;&amp; !returnUrl.StartsWith("/\\"))
              {
                  return Redirect(returnUrl);
              }
              else
              {
                  return RedirectToAction("Index", "Home");
              }
          }
          else
          {
              ModelState.AddModelError("", 
                  "The user name or password provided is incorrect.");
          }
      }
  
      // If we got this far, something failed, redisplay form
      return View(model);
  }
  </code></pre>
  
  <p>And from what I have read, I should be trying to use DbContext to access the property of a given field, similar to:</p>
  
  <pre><code>using (var context = new DbContext())
  {
      var svc100 = context.SVC00100.Where(t =&gt; 
                          t.TECHEMAIL.Contains("model.UserName")
  
      // Read the current value of the Name property
      Session["Name"] = context.Entry(svc100).Property(u =&gt;
                                                   u.Name).CurrentValue;
  }
  </code></pre>
  
  <p>Now... How do I determine what should be used in place of DbContext() in the second code block?  If I try to use the drop down and pick what I need, I do not see anything relating to my Entity (CPLUEntities) that contains the DbContext phrase.</p>
  
  <p>Some of the links I've discovered:</p>
  
  <p><a href="https://stackoverflow.com/questions/5431243/implement-custom-validateuser-in-membershipprovider">Implement custom “ValidateUser” in MembershipProvider</a></p>
  
  <p><a href="http://msdn.microsoft.com/en-US/data/jj592677" rel="nofollow noreferrer">Entity Framework Working with Property Values</a></p>
  
  <p><a href="http://blogs.msdn.com/b/adonet/archive/2011/01/30/using-dbcontext-in-ef-feature-ctp5-part-5-working-with-property-values.aspx" rel="nofollow noreferrer">Using DbContext in EF 4.1 Part 5: Working with Property Values</a></p>