类型中的每个属性名称必须唯一

时间:2019-04-25 05:22:08

标签: c# entity-framework

当我在数据库中创建一个视图时,ef将更改此错误消息。 SPL和分段是表,vwSPLGrade是视图。

select spl.*,grade.SegmentationDisplay from SPL as spl
left join Segmentation as grade
on UPPER(spl.HCPEID) = UPPER(grade.HCPEID)
where spl.status = 1 and grade.status =1

该怎么解决这个问题?

public class SPL : Entity
{
    public SPL() { }

    public string TA { get; set; }
    public string TerritoryCode { get; set; }
    public string YearMonth { get; set; }
    public string HCPEID { get; set; }
    public string HCOVeevaId { get; set; }
    public DateTime? FocusDate { get; set; }
    public Guid? SurveyId { get; set; }
    public bool? IsSPL { get; set; }
}

public class Segmentation : Entity
{
    public Segmentation() { }

    public string TA { get; set; }
    public string HCPEID { get; set; }
    public string SegmentationDisplay { get; set; }
    public string SegmentationCalculate { get; set; }
    public string SegmentationMRManual { get; set; }
    public string SegmentationAdminChange { get; set; }
    public Guid? SurveyId { get; set; }
    public string TerritoryCode { get; set; }
    public string YearMonth { get; set; }
}

public class vwSPLGrade : Entity
{
    public vwSPLGrade() { }

    public string TA { get; set; }
    public string TerritoryCode { get; set; }
    public string YearMonth { get; set; }
    public string HCPEID { get; set; }
    public string HCOVeevaId { get; set; }
    public DateTime? FocusDate { get; set; }
    public Guid? SurveyId { get; set; }
    public bool? IsSPL { get; set; }
    public string Grade { get; set; }
}

public class SPLMap : EntityTypeConfiguration<SPL>
{
    public SPLMap()
    {
        this.HasKey(t => t.Id);

        this.Property(t => t.Id)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

        this.ToTable("SPL");
        this.Property(t => t.Id).HasColumnName("Id");
        this.Property(t => t.TA).HasColumnName("TA");
        this.Property(t => t.TerritoryCode).HasColumnName("TerritoryCode");
        this.Property(t => t.YearMonth).HasColumnName("YearMonth");
        this.Property(t => t.HCPEID).HasColumnName("HCPEID");
        this.Property(t => t.HCOVeevaId).HasColumnName("HCOVeevaId");
        this.Property(t => t.FocusDate).HasColumnName("FocusDate");
        this.Property(t => t.SurveyId).HasColumnName("SurveyId");
        this.Property(t => t.IsSPL).HasColumnName("IsSPL");

        this.Property(t => t.Status).HasColumnName("status");
        this.Property(t => t.CreateBy).HasColumnName("create_by");
        this.Property(t => t.CreateDate).HasColumnName("create_date");
        this.Property(t => t.LastModifiedBy).HasColumnName("last_modified_by");
        this.Property(t => t.LastModifiedDate).HasColumnName("last_modified_date");

    }
}

public class SegmentationMap : EntityTypeConfiguration<Segmentation>
{
    public SegmentationMap()
    {


        this.HasKey(t => t.Id);


        this.Property(t => t.Id)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

        this.ToTable("Segmentation");
        this.Property(t => t.Id).HasColumnName("Id");
        this.Property(t => t.TA).HasColumnName("TA");
        this.Property(t => t.HCPEID).HasColumnName("HCPEID");
        this.Property(t => t.SegmentationDisplay).HasColumnName("TerritoryCode");
        this.Property(t => t.SegmentationCalculate).HasColumnName("SegmentationCalculate");
        this.Property(t => t.SegmentationMRManual).HasColumnName("SegmentationMRManual");
        this.Property(t => t.SegmentationAdminChange).HasColumnName("SegmentationAdminChange");
        this.Property(t => t.SurveyId).HasColumnName("SurveyId");
        this.Property(t => t.TerritoryCode).HasColumnName("TerritoryCode");
        this.Property(t => t.YearMonth).HasColumnName("YearMonth");

        this.Property(t => t.Status).HasColumnName("status");
        this.Property(t => t.CreateBy).HasColumnName("create_by");
        this.Property(t => t.CreateDate).HasColumnName("create_date");
        this.Property(t => t.LastModifiedBy).HasColumnName("last_modified_by");
        this.Property(t => t.LastModifiedDate).HasColumnName("last_modified_date");

    }
}

public class vwSPLGradeMap : EntityTypeConfiguration<vwSPLGrade>
{
    public vwSPLGradeMap()
    {
        this.ToTable("VW_SPLGrade");
        this.Property(t => t.Id).HasColumnName("Id");
        this.Property(t => t.TA).HasColumnName("TA");
        this.Property(t =>t.TerritoryCode).HasColumnName("TerritoryCode");
        this.Property(t => t.YearMonth).HasColumnName("YearMonth");
        this.Property(t => t.HCPEID).HasColumnName("HCPEID");
        this.Property(t => t.HCOVeevaId).HasColumnName("HCOVeevaId");
        this.Property(t => t.FocusDate).HasColumnName("FocusDate");
        this.Property(t => t.SurveyId).HasColumnName("SurveyId");
        this.Property(t => t.IsSPL).HasColumnName("IsSPL");
        this.Property(t => t.Grade).HasColumnName("Grade");
        this.Property(t => t.Status).HasColumnName("status");
        this.Property(t => t.CreateBy).HasColumnName("create_by");
        this.Property(t => t.CreateDate).HasColumnName("create_date");
     this.Property(t=>t.LastModifiedBy).HasColumnName("last_modified_by");
this.Property(t=>t.LastModifiedDate).HasColumnName("last_modified_date");
    }
}

1 个答案:

答案 0 :(得分:0)

完整的错误消息是

  

在模型生成过程中检测到一个或多个验证错误:   TerritoryCode:名称:类型中的每个属性名称都必须是唯一的。属性名称“ TerritoryCode”已经定义。

TerritoryCode映射到列名public class SegmentationMap : EntityTypeConfiguration<Segmentation> { public SegmentationMap() { this.HasKey(t => t.Id); this.Property(t => t.Id) .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); this.ToTable("Segmentation"); this.Property(t => t.Id).HasColumnName("Id"); this.Property(t => t.TA).HasColumnName("TA"); this.Property(t => t.HCPEID).HasColumnName("HCPEID"); //it should be this.Property(t => t.SegmentationDisplay).HasColumnName("SegmentationDisplay"); this.Property(t => t.SegmentationDisplay).HasColumnName("TerritoryCode"); this.Property(t => t.SegmentationCalculate).HasColumnName("SegmentationCalculate"); this.Property(t => t.SegmentationMRManual).HasColumnName("SegmentationMRManual"); this.Property(t => t.SegmentationAdminChange).HasColumnName("SegmentationAdminChange"); this.Property(t => t.SurveyId).HasColumnName("SurveyId"); this.Property(t => t.TerritoryCode).HasColumnName("TerritoryCode"); this.Property(t => t.YearMonth).HasColumnName("YearMonth"); this.Property(t => t.Status).HasColumnName("status"); this.Property(t => t.CreateBy).HasColumnName("create_by"); this.Property(t => t.CreateDate).HasColumnName("create_date"); this.Property(t => t.LastModifiedBy).HasColumnName("last_modified_by"); this.Property(t => t.LastModifiedDate).HasColumnName("last_modified_date"); } } 时出错。

az acr build --subscription $SubscriptionId -r $registry --platform Windows -f Dockerfile -t XYZ:v$version obj