小编Ves*_*rov的帖子

EF Core 属性值转换在派生实体配置中不起作用

我有一个通用 EF BaseEntityConfiguration 类,用于设置基本属性(如主键、用于软删除的属性、查询过滤器等)以及存储 System.Type 和 JSON 属性的实体的派生配置。如果我不使用泛型类而仅实现 IEntityTypeConfiguration,则值转换将起作用并且不会出现错误。但是,如果我从基类继承,则会遇到有关在不进行任何转换的情况下保存类型和对象的 EF Core 问题。从基类继承并且不需要转换的其他配置可以正常工作。

错误:

Error: The property 'MessageLog.Data' could not be mapped because it is of type 'object', which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.

public class MessageLogConfiguration
        //: IEntityTypeConfiguration<MessageLog>
        : BaseEntityConfiguration<MessageLog, int>
    {
        public MessageLogConfiguration(ILogger<MessageLogConfiguration> logger)
           : base(logger)
        { }

        public override void Configure(EntityTypeBuilder<MessageLog> builder)
        {
            base.Configure(builder); …
Run Code Online (Sandbox Code Playgroud)

.net c# entity-framework entity-framework-core asp.net-core

5
推荐指数
1
解决办法
3092
查看次数