TPT需要显式模型构建器声明 [英] TPT needs explicit model builder declaration
问题描述
最好完全摆脱modelBuilder中TPT类的声明,并根据它们的命名自动化它们。
  ; public abstract class Property
{
; public int PropertyID
       {
            的 get ;
set ; }
}
public class 构建 : 财产
{
; public string BuildingName
    {
            的获得跨度> ; set ;
  ; }
}
public class 众议院 : 财产
& nbsp; {
public 串跨度>  HouseAddress
         {
        &NBSP ;   的获得跨度>;
           &NBSP ; set ;
}
}
我需要指定以下的modelBuilder声明
<预风格= "font-family:索拉">&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; modelBuilder.Entity<的属性跨度>>()ToTable(的"属性" 跨度>);
&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; modelBuilder.Entity& lt; House >()。ToTable(" House" );
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; modelBuilder.Entity<的建筑跨度>>()ToTable。 (" Building" );
或者它会给我错误
无效的列名'BuildingName'。
无效的列名'HouseAddress'。
无效的列名'Discriminator'。
在最终版本中修复此问题会很好。
NeoTech
您好,
我假设您要映射到现有数据库?
Code First默认为TPH而不是TPT,因此它需要一个Properties表,每个属性都有一列,另一列用作鉴别器。我们默认使用TPH,因为它提供了三种映射策略(TPH,TPT和TPC)中功能和
性能的最佳组合。
~Rowan
It would be good to get rid of declaration of TPT classes from modelBuilder completely and automap them based on their naming.
public abstract class Property
{
public int PropertyID
{
get;
set;
}
}
public class Building : Property
{
public string BuildingName
{
get;
set;
}
}
public class House : Property
{
public string HouseAddress
{
get;
set;
}
}
I need to specify the below modelBuilder declaration
modelBuilder.Entity<Property>().ToTable("Property");
modelBuilder.Entity<House>().ToTable("House");
modelBuilder.Entity<Building>().ToTable("Building");
or it would give me error
Invalid column name 'BuildingName'.
Invalid column name 'HouseAddress'.
Invalid column name 'Discriminator'.
It would be good to get this fixed in the final release.
NeoTech
Hi,
I assume you are mapping to an existing database?
Code First actually defaults to TPH rather than TPT, so it expects a single Properties table with a column for each property and an additional column to use as a discriminator. We default to TPH because it offers the best combination of functionality and performance out of the the three mapping strategies (TPH, TPT & TPC).
~Rowan
这篇关于TPT需要显式模型构建器声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!