entity framework 4 - EF4: Creating a 0..1 to Many Association -
i trying add association didn't have originally. realized 2 tables technically related, , navigation properties might simplify have otherwise had manually. tables , keys this:
import primary key: number : int32 date : datetime hour primary key: departmentid : int32 usernumber : int32 date : datetime
the association named importhour. import.number maps hour.usernumber, , import.date maps hour.date. trying add association 0..1 on import, , * on hour navigation properties , no additional foreign keys. when this, designer tells me association not mapped. if generate ddl, creates new fields hours.import_date , hours.import_number (hours actual database table name hour entity). if manually map fields, end following error:
error 3021: problem in mapping fragments starting @ line 332: each of following columns in table hours mapped multiple conceptual side properties: hours.date mapped <importhour.hour.date, importhour.import.date> hours.usernumber mapped <importhour.hour.usernumber, importhour.import.number>*
i not sure happening, , don't think understand 'mapping' process enough figure out. seems if wants quintuple key, instead of realizing 1 key maps other. @ other one-to-many associations, , not have table mappings; think have referential constraints instead, can't have referential constraint 0..1 many association.
there 2 ways define relation in case must use foreign key association. means once draw association in entity model must select , define referential constraints.
you cannot have 0..1 on import
because in such case usernumber
, date
in hour
must nullable. relation mean. if no principal entity exists (import
) fk properties in dependent entity (hour
) null.
btw. using datetime
in primary key not recommended.
Comments
Post a Comment