c# - Entity Framework: field of composite key cannot be nullable? -
i have model composite key - row key:
public class item { [key, column(order = 0)] public int userid { get; set; } [key, column(order = 1)] public datetime? date { get; set; } } running code below throws exception dbentityvalidationexception message: the date field required.:
var = new item { date = null, userid = 2 }; m_entities.items.add(it); m_entities.savechanges(); // throws exception (m_entities usual dbcontext descendant items defined dbset<item>) why date required if can null (declared datetime?) ? , how allow null valid value date?
answer raphael lead me search. here why not possible (answer cobsy):
what's wrong nullable columns in composite primary keys?
in short: null == null -> false
wierd. solution me add id column model.
btw: mysql allow me not define primary key, i'm allowed have such schema - ef complains not defining key :-(.
Comments
Post a Comment