EFDAL: Verifier Miss?

May 20, 2011 at 12:05 AM

I had a table in my schema which had a nullable int field that I also specified as being unique in the schema editor. Making it unique was silly, in retrospect, because many of the records would likely have a null value for that field, which would most definitely mean they weren't unique :). 

I'd set the unique property after working with the table for a while, and, as luck would have it, there actually was only one record with a null value in the field in question.

However, when I ran the app where the schema is used, Entity Framework threw the following startup exception:

Multiplicity is not valid in Role 'VersionedAsset' in relationship 'FK__SiteContent_VersionedAsset'. Because all the properties in the Dependent Role are nullable, multiplicity of the Principal Role must be '0..1'.

After fixing that particular problem I ran into similar situations that generated different exceptions on startup. They all had to do with my having made a field unique when it was also part of a foreign key relationship. Not all of the fields involved were nullable (in fact, must of them weren't).

Is this a limitation of EF? Or invalid/unsupported database design? Can the nHydrate verifier catch such things if they're errors?

- Mark

Coordinator
May 21, 2011 at 3:37 AM

This issue will be resolved in the next version. AllowNull will be automatically on for a IsUnique field. You are right this should be be a validation. The generation will be fine then.