Case Sensitive with Entity Framework Core 7 code-first
I create a database with Entity Framework Core 7 code-first. I look at other questions, but none of them have a concrete answer. I try to save these two names as different rows to my table:
Male & male
This is my class for attribute:
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class CaseSensitive : Attribute
{
public CaseSensitive()
{
IsEnabled = true;
}
public bool IsEnabled { get; set; }
}
This is my db model:
public sealed class Gender : AggregateRoot, IAuditableEntity
{
private Gender(Guid id, ItemName name) : base(id)
{
Name = name;
ModificationReason ??= Reason.Create("Default").Value;
}
private Gender()
{
}
[Required]
[CaseSensitive]
public ItemName Name { get; set; }
public bool IsActive { get; set; } = true;
public DateTime CreatedOnUtc { get; set; }
public Guid? CreatedOnBy { get; set; }
public DateTime? ModifiedOnUtc { get; set; }
public Guid? ModifiedOnBy { get; set; }
public Reason ModificationReason { get; set; }
}
This is EF Core DbContext
from version 6.0+:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Add
(new AttributeToColumnAnnotationConvention<CaseSensitive, bool>
("CaseSensitive", (property, attributes) => attributes.Single().IsEnabled));
}
But this doesn't work in EF Core v7 anymore. How can I make it work with EF Core 7?
Comments
Post a Comment