by Vahid
29. April 2011 18:00
I was working with Entity Framework and I needed to update a single column of a row in the database. basically I was logging the users visit to a web site (ASP.NET). so first time user lands in the website I create a record in database and keep the id in the session. when user’s session times out I needed to update the row and set the exit time of the user. it sounded a bit difficult to do this with Entity Framework I did it this way and worked pretty well:
public void UpdateVisit(long id, string userId)
{
//id (row id) comes from the user so we create an object and assign the id
VisitInformation visitInformation = new VisitInformation() { ID = id };
try
{
using (var context = new TravIranLogEntities())
{
//Here we attach the object to the context and set the state to unchanged
context.Entry(visitInformation).State = EntityState.Unchanged;
//update the column(s) that you need to modify
visitInformation.UserId = userId;
//Send the informatin back to the Database
context.SaveChanges();
}
}
catch (Exception ex)
{
LogManager.Log("Error in UpdateVisit for user id", ex, LogMode.LogAndEmai);
}
}
by Vahid
27. April 2011 16:27
Just found these set of post in the MSDN site for getting started with EntityFramework 4.1. if you are new to entityframework this is a good point to start
http://msdn.microsoft.com/en-us/data/gg192989
by Vahid
17. February 2009 15:32
need to know about new cool features in visual studio 2010? check this link which describes new features for entity framwork in vs 2010
http://blogs.msdn.com/efdesign/archive/2009/01/22/customizing-entity-classes-with-t4.aspx
by Vahid
17. February 2009 15:17
browsing internet i found this document about ado.net entity framework which comes with microsoft .net framework 3.5 sp1.
check it out at:
(reference http://cid-245ed00edb4c374e.skydrive.live.com/self.aspx/Public/entity%20framework%20learning%20guide.pdf)