All:
Our company is working on a ASP.NET application that uses Entity Framework. The Entity Framework Model First approach was taken to create the database tables and POCOs Moreover, we are using Effort Testing Tool for Entity Framework and NUnit Framework in order to conduct Unit Testing.
At present, we are trying some CRUD operations on Customer and Account Business Entities ASP.NET application.
Every Customer has the option of having at most one account. Here is how the relationship between the 2 tables looks like in a Database Diagram:
Our application also keeps track of changed tracking of entities and relationships between entities.
We have the following code example with populated Customer and Account business entries:
Customer custFour = new Customer { CustomerID = "4 ", Orders = new HashSet<Order>(), CustomerDemographics = new HashSet<CustomerDemographic>(), CompanyName = "FC Barcelona", ContactName = "Lionel Messi", ContactTitle = "current top basket ball player", Address = "344 testing street", City = "Buenos Aires", Region = "Oklahoma", PostalCode = "4498", Country = "Argentina", Phone = "2344949494", Fax = "33325" };
Account acctFour = new Account { UserName = "lmessi", Password = "myteamlostworldcupmatch", Customer = custFour, AccountRoleMaps = new HashSet<AccountRoleMap>() };
To keep it brief, we also invoke a line of code like the following so that the Entity Framework DbContext can save the Customer and Account entities mentioned above, and also the relationship between the Customer and Account entities:
_context.Set<Account>().Add(acctFour);
_context.SaveChanges();
As the point of execution goes on, we ultimately reach the following excerpt of code:
List<System.Data.Entity.Core.Objects.ObjectStateEntry> allAddModDelItems = ((IObjectContextAdapter)_context).ObjectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Modified | EntityState.Deleted).ToList();
foreach (var osEnt in allAddModDelItems)
{
}
The above excerpt of code retrieves all the Objects and Relationships between Objects that have been Added, Modified and Deleted.
I already checked the System.Data.Entity.Core.Objects.EntityEntry for the Customer and the System.Data.Entity.Core.Objects.EntityEntry for the Account, and they have Valid Business Data.
Sadly, the System.Data.Entity.Core.Objects.RelationshipEntry has Entity as null and the EntityKey as null which seems to be wrong because the System.Data.Entity.Core.Objects.RelationshipEntry should reflect the relationship between the Account and Customer objects that I created. Why is the System.Data.Entity.Core.Objects.RelationshipEntry Wrong? In other words, Why are the System.Data.Entity.Core.Objects.RelationshipEntry's Entity and the EntityKey properties null?
http://msdn.microsoft.com/en-us/library/system.data.objects.objectstateentry.entity%28v=vs.100%29.aspx
The Entity property returns null when the ObjectStateEntry is associated with a RelationshipSet entry instead of an entity type instance.
Therefore, it makes sense for Entity and the EntityKey properties to be null