c# - Single Row Table in Entity Framework 6 -
i couldn't find solution problem title makes clear want.
is possible create single row table (i need store boolean value in table)? , how can configure constraint fluent api?
you make 1 of columns primary , allow 1 value. unfortunately fluent api doenst support default value
public class statusidentifer { [defaultvalue("1")] [key] public int id {get; set}; //set can removed here? public bool status {get:set;} //your boolean value }
the trick not expose set methods id.
at database level can still break paradigm. answer here tells how create check constraint
public void initializedatabase(myrepository context) { if (!context.database.exists() || !context.database.modelmatchesdatabase()) { context.database.deleteifexists(); context.database.create(); context.objectcontext.executestorecommand("create unique constraint..."); context.objectcontext.executestorecommand("create index..."); context.objectcontext.executestorecommand("etc..."); } }
Comments
Post a Comment