Click here to Skip to main content
15,897,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
using (var context = new BloggingContext())
{
    var blog = new Blog { Name = "ADO.NET Blog" };
    context.Blogs.Add(blog);
    context.SaveChanges();
}



using (var context = new BloggingContext())
{
    var blog = new Blog { Name = "ADO.NET Blog" };
    context.Entry(blog).State = EntityState.Added;
    context.SaveChanges();
}

What was the difference between above and which will give best performance
Posted
Updated 9-Jan-14 2:21am
v2

1.You should use the first case, because the code is more clear! As I know there is no difference between them regarding the performance.

2. In generally when you add and/or modify objects by using entity framework you should add multiple adding and changes of the objects and only when you relay finish with them to invoke "SaveCahnges()" for the entire set; in other words the "SaveChanges()" invocation should not be done to frequent for each object if is possible, and this will give you performance.
 
Share this answer
 
Please visit Following Link
http://msdn.microsoft.com/en-in/data/jj592676.aspx[^]
this will gives you full information about it.
 
Share this answer
 
Check this sample application:

Entity Framework for Beginners[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900