I am working on a C# ASP.NET MVC 5 web application with EF 5. Mapping of my database tables using EF generates a DbContext
class and an .edmx
file. Today, I was reading a great article about creating generic DAL classes, but I stopped on the following sentence:
Note that using the Entry method to change the state of an entity will only affect the actual entity that you pass in to the method. It won’t cascade through a graph and set the state of all related objects, unlike the DbSet.Add method.
That contradicts what is mentioned in these questions:
- http://forums.asp.net/p/2015170/5803192.aspx
- http://forums.asp.net/p/2060606/5943259.aspx
- Difference between DbSet.Add(entity) and entity.State = EntityState.Added
- What is the difference between IDbSet.Add and DbEntityEntry.State = EntityState.Added?
In all the above questions’ answers, all users mentioned that using System.Data.EntityState.Added
is exactly the same as using DbSet.Add
. But the article I mentioned first states that using System.Data.EntityState.Added
will not cascade through the graph.
Based on my test, I conclude that using System.Data.EntityState.Added
will cascade through the graph same as in the DBset.Add
case. Is the article wrong, or is it my test and the Q&A?