EF4: splitting a table into two objects using POCOs - why am I getting an exception?

I have one Courses table mapped to two Course and CourseDetails objects .
Both have POCO classes with virtual navigation properties .
Both objects use the same identifier (Identity on the course, but not on CourseDetail).
Mapping between objects is a " referential integrity constraint " not in the "mapping" window.
The course is a principle of limitation.

I am using LazingLoading and ProxyCreationEnabled .

After calling context.SaveChanges (), the connections look great (identifiers, links, and data).

When accessing the course. CourseDetails from the loop in context. Courses. I get empty CourseDetails fields created by the course constructor, instead of the actual CourseDetails !?

When I call context.LoadProperty (course, c => c.CourseDetails) I get an InvalidOperationException with the message:

" Multiplicity violation. The role of the 'CourseDetails' relationship 'OrmComparisons.EFPocos1.CourseDetailsCourse' has a multiplicity of 1 or 0..1. "

Question 1: Why is Course.CourseDetails empty?
Question 2: Why am I getting an exception?
Question 3: What should I do instead?

I can share the solution file + sql if someone wants to look.

+3
source share
1 answer

After comparing my own POCOs with the created POCOs template,
I noticed Fix___ methods that are designed to fix navigational properties.
Some, like all other types of relationships (from one to many, from many to many, inheritance)
work with virtual properties and lazy loading.
Only the table shares a one-to-one relationship.

- t4 POCOs, POCO {get; ; }.

0

All Articles