c# - Entity Framework IsUnique and accept Nulls -
c# - Entity Framework IsUnique and accept Nulls -
how can create code first property accepts null values it's [index(isunique=true)]
?
for example: passport number should't repeated, ergo isunique
, if user doesn't insert one, defaults null, accepts multiple nulls.
since not unique then, cannot way. can manage it, attaching table:
public class person { public int id { get; set; } } public class passport { [key] public int personid { get; set; } [foreignkey("personid")] public person person { get; set; } [index(isunique=true)] public string passportid { get; set; } }
be aware, there countries, not allow storing such numbers.
c# entity-framework
Comments
Post a Comment