Entity Framework with 6NF Tables
In my model, I have two tables with a 1:0..1 relationship between them:
(Example names for the sake of simplicity)
Event
----------
EventId (int; PK)
StartDate (date)
EndDate (date)
EventTime
---------
EventId (int; PK, FK)
StartTime (time)
EndTime (time)
(As this is 6NF, none of these columns are nullable)
In my edmx, I'm trying to map these two tables into a single entity where StartTime
and EndTime
are null on the entity, but not in the database. While this doesn't strictly represent what's possible in the database (the database would require either valid values for both start and end time, or no value for either), I was hoping to have EF make the decision as to whether or not an EventTime
row needed to exist depending on whether or not the StartTime
and EndTime
values were set on the entity, and throw an exception if only one was set.
It doesn't seem that this is possible, at least how I have it configured. I added two scalar properties to the Event
class and mapped them to the EventTime
table. The mapping was created successfully, but when I try to compile my precompiled views I get the following compiler开发者_StackOverflow社区 error:
Error 108 Running transformation: Problem in mapping fragments starting at line 0:Non-nullable column EventTime.EndTime in table EventTime is mapped to a nullable entity property.
Obviously, I can deal with the EventTime
entity as a distinct entity (as it actually is in the database), but I was hoping to simplify the API surface by doing it this way. Is what I'm shooting for possible?
Given the lack of response to this question, I am going to assume that it is not possible.
精彩评论