I couldn't find a solution for this problem but the title makes clear what I want.
Is it possible to create a single row table (I only need to store a boolean value in a table)? And how can I configure this constraint with Fluent API?
you could make one of the columns as primary and also allow only one value. unfortunately fluent api currently doenst support default value
public class StatusIdentifer
{
[DefaultValue("1")]
[Key]
public int id {get; set}; //set can be removed here?
public bool status {get:set;} //your boolean value
}
the trick is not to expose any set methods for id.
at database level you can still break the paradigm. The answer here tells how to create a 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...");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With