TPC在CodeFirst-Migration中不起作用

时间:2016-01-19 08:52:07

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

我有以下课程:

 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; }
}

我在Table下面并继承BaseAttachment

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

和此:

 public class Attachment:BaseAttachment
{

}

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

BaseAttachment,ProductCategory

而不是一个表(BaseAttachment)。 为什么?

1 个答案:

答案 0 :(得分:0)

我是ProductCategoryConfig的配置类,下面是Set TableName:

 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");