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

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -