Comments (1)
I took a look at this, and it doesn't seem to be a problem:
Model
class Program
{
static async Task Main(string[] args)
{
await using var ctx = new BlogContext();
await ctx.Database.EnsureDeletedAsync();
await ctx.Database.EnsureCreatedAsync();
}
}
public class BlogContext : DbContext
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Parent>();
modelBuilder.Entity<Sibling1>().Property(s => s.OrderStatus).HasColumnName("OrderStatus");
modelBuilder.Entity<Sibling2>().Property(s => s.OrderStatus).HasColumnName("OrderStatus");
}
}
public class Parent
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Sibling1 : Parent
{
public OrderStatus OrderStatus { get; set; }
}
public class Sibling2 : Parent
{
public OrderStatus OrderStatus { get; set; }
}
public enum OrderStatus
{
Active,
Completed
}
Generates the following:
CREATE TABLE "Parent" (
"Id" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"Name" text NULL,
"Discriminator" text NOT NULL,
"OrderStatus" integer NULL,
CONSTRAINT "PK_Parent" PRIMARY KEY ("Id"),
CONSTRAINT "CK_Parent_Discriminator_Constraint" CHECK ("Discriminator" IN ('Parent', 'Sibling1', 'Sibling2')),
CONSTRAINT "CK_Parent_OrderStatus_Enum_Constraint" CHECK ("OrderStatus" IN (0, 1))
);
This seems to be because the CheckConstraint is defined on the two different entities (not on the table), so no clash. Later, the relational model deduplicates the two constraints.
from efcore.checkconstraints.
Related Issues (20)
- [Request] implement ISJSON check HOT 8
- Support the new 8.0 validation attributes HOT 3
- The regular expression generated by URLAttribute is insufficient HOT 1
- Doesn't generate any check constraint when targeting a mysql database
- [Request] Implement Required attribute to disallow empty strings HOT 2
- Initial SQL Server regex setup does not work HOT 11
- Range check constraints not generated for some datatype HOT 12
- Feature Request: Support Fluent Configuration with Lambda Expressions HOT 2
- Support [Base64String]
- Check constraint as an expression instead of sql? HOT 2
- Add additional URL protocols to Common Url pattern HOT 2
- Adds unexpected constraints when using together with [Required] attribute HOT 4
- UseEnumCheckConstraints does not respect DbContext conventions
- Use new regex support on Azure SQL HOT 4
- Range check doesn't work for decimals HOT 4
- String Length constraint on owned entity HOT 2
- InvalidOperationException with in-memory DB HOT 6
- Allow lowercase naming, for example `ck` instead of `CK` HOT 8
- feat: Add Constraint for brazilian official info HOT 2
- Don't generate enum constraints for PostgreSQL native enum mapping
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from efcore.checkconstraints.