我一直收到这个错误消息:
异常详细信息:MySql.Data.MySqlClient.MySql Exception:“字段列表”中的未知列“Extent1.RuleType”
我的映射:

public abstract class AlertRule
{
    private DateTime? _updateDateTime = DateTime.Now;

    [Key]
    public int Id { get; set; }

    public int TemplateId { get; set; }
    public virtual AlertRuleTemplate Template { get; set; }

    public string RuleType
    {
        get
        {
            if (Template == null)
                return null;
            return Template.Name;
        }
    }
}
public class AlertOutageRule:AlertRule
{
    public virtual List<AlertRuleOutage> AlertRuleOutages { get; set; }
}
public class AlertMissingRule:AlertRule{}
public class AlertMetadataRule:AlertRule{}

        public DbSet<AlertRule> AlertRules { get; set; }

        modelBuilder.Entity<AlertRule>()
            .Map<AlertOutageRule>(m => m.Requires("RuleType").HasValue("NewsOutage"))
            .Map<AlertMetadataRule>(m => m.Requires("RuleType").HasValue("NewsMetadata"))
            .Map<AlertMissingRule>(m => m.Requires("RuleType").HasValue("NewsMissing"));
            //.Property(m => m.TemplateId).HasColumnType("int");

        modelBuilder.Entity<AlertRule>().ToTable("AlertRule");

最佳答案

public string RuleType定义为只读(noset{..})。
EF不会将此属性与数据库映射。查看您的数据库架构它只生成2列(Id,TemplateId)

10-07 14:48