我们首先更新我们的数据库,并有3个表:
Zoo_Keeper
Zoo_Mammal
Zoo_Reptile
(为简单起见,更改了名称!)
一个饲养员可以养很多哺乳动物。
一个饲养员可以有许多爬行动物。
链接到Zoo_Keeper的Zoo_Mammal上的外键。
链接到Zoo_Keeper的Zoo_Reptile上的外键。
在EntityFramework中,我们使用“从数据库更新模型”功能,我们的Zoo_Keeper自动生成的类如下所示:
namespace ZooApp.DataAccess.EntityDataModels
{
using System;
using System.Collections.Generic;
public partial class Zoo_Keeper
{
public Zoo_Keeper()
{
this.Mammals = new HashSet<Zoo_Mammal>();
this.Zoo_Reptile = new HashSet<Zoo_Reptile>();
}
//some properties
public virtual ICollection<Zoo_Mammal> Mammals { get; set; }
public virtual ICollection<Zoo_Reptile> Zoo_Reptile { get; set; }
}
}EF是如何想出ICollections的名字的?(哺乳动物,Zoo_Reptile)
我们很困惑为什么一个去掉了'Zoo‘前缀,而另一个却没有。是什么原因导致EF以不同的方式命名关系呢?
我们检查了FK名称,但这两个名称看起来是一致的:
FK_Zoo_Mammal_Zoo_Keeper
FK_Zoo_Reptile_Zoo_Keeper
发布于 2017-04-27 20:45:19
使用NavigationProperty标记在.edmx文件中配置了这些自定义名称:
<EntityType Name="Zoo_Keeper">
...
<NavigationProperty Name="Mammals" Relationship="Self.FK_Zoo_Mammal_Zoo_Keeper" FromRole="Zoo_Keeper" ToRole="Zoo_Mammal" />
</EntityType>https://stackoverflow.com/questions/40887255
复制相似问题