【问题标题】:TPC doesnt work in CodeFirst-MigrationTPC 在代码优先迁移中不起作用
【发布时间】:2016-01-19 08:52:06
【问题描述】:

我有以下课程:

 public abstract class BaseAttachment
{
    public Guid BaseAttachmentId { get; set; }
    public string FileName { get; set; }
    public string FileExtension { get; set; }
    public string FileSize { get; set; }
    public Folder Folder { get; set; }
    public Guid? FolderId { get; set; }
    public byte[] RowVersion { get; set; }
}

我有下面的表和继承BaseAttachment

public class ProductGallery : BaseAttachment
{
    public ProductHeader ProductHeader { get; set; }
    public Guid? ProductHeaderId { get; set; }
}

还有这个:

 public class Attachment:BaseAttachment
{

}

当运行项目和创建数据库时,我有下表:

BaseAttachment,ProductCategory

而不是一张桌子 (BaseAttachment) 。 为什么?

【问题讨论】:

    标签: entity-framework ef-code-first migration code-first


    【解决方案1】:

    我是 ProductCategoryConfig 的一个配置类,如下所示:

     public class ProductGalleryConfig:EntityTypeConfiguration<ProductGallery>
    {
       public ProductGalleryConfig()
       {
           ToTable("ProductGallery");
           Property(row => row.Code).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
           Property(row => row.RowVersion).IsRowVersion();
           HasRequired(row => row.ProductHeader).WithMany(row => row.Galleries).HasForeignKey(row => row.ProductHeaderId).WillCascadeOnDelete(false);
       }
    }
    

    并在 Line 下方评论及其修复。

    //    ToTable("ProductGallery");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-24
      • 1970-01-01
      • 1970-01-01
      • 2016-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多