2

我不断收到此错误消息:

异常详细信息:MySql.Data.MySqlClient.MySqlException:“字段列表”中的未知列“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");
4

1 回答 1

2

定义为public string RuleType只读(否set{..})。

EF 不会将此属性与数据库进行映射。查看您的数据库架构,它将仅生成 2 列(Id,TemplateId)

于 2012-12-28T03:40:58.657 回答