I have a .Net 7 server app and im using Entity Framework code first approach and I wonder, is there any way to enforce the regex pattern on the property directly on database using fluent api (entity configuration file)?
I've tried something like:
builder.HasIndex(e => e.Name)
.HasDatabaseName("IX_Name_Regex")
.HasFilter("[Name] ~ '^[a-zA-Z0-9_]*$'")
.IsUnique();
and:
builder.Property(it => it.Name)
.HasMaxLength(256);
.HasAnnotation("Name_Regex", @"^[a-zA-Z0-9_]*$");
and some other mix but none of them are working.
I found an answer: EF - How to define a regular expression property using fluent EntityTypeConfiguration API? but its 10 y/o, so I wonder, maybe it is a way to do this?