efcore / EFCore.CheckConstraints

An Entity Framework Core plugin to automatically add check constraints in various situations
Apache License 2.0
290 stars 14 forks source link

Check constraint as an expression instead of sql? #143

Closed voroninp closed 6 months ago

voroninp commented 6 months ago

I have two columns StartDate EndDate and I'd like to express the constraint with the expression:

HasCheckContaint(entity => entity.StartDate < entity.EndDate);

Sure, I can do this just with a sql string, but then I need to specify the exact column names properties are mapped to.

roji commented 6 months ago

Duplicate of https://github.com/dotnet/efcore/issues/11001

roji commented 6 months ago

Note that this plugin (EFCore.CheckConstraints) is about automatically creating check constraints for you; if you'd like to define your own check constraints (regardless of whether you do that via SQL or an expression), then you're using EF directly and not this plugin.