Not*_*ple 12 c# entity-framework
我想知道实体框架在导航属性的命名/生成方面遵循的规则.我观察过几个似乎没有意义的场景,所以我想知道是否有人确切知道这些是如何工作的.
场景1:
public class Post
{
public int Id { get; set; }
public User Author { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
生成

即.默认情况下,导航属性会生成名为[PropertyName] _Id的FK
场景2:
有意义的是,如果EF在您手动指定FK ID时生成格式[PropertyName] _Id等属性,则它将遵循相同的规则:
public class Post
{
public int Id { get; set; }
public int? Author_Id { get; set; }
public User Author { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
生成

如您所见,这不会自动注册为nav属性.
场景3:
如果它不适用于场景2,为什么它适用于备用命名约定?
public class Post
{
public int Id { get; set; }
public int? AuthorId { get; set; }
public User Author { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
生成

有关导航属性检测和生成的规则是什么?
Lad*_*nka 12
这是预期的行为,它基于EF的两个不同的约定
NameOfNavigationProperty_NameOfRelatedPK此约定遵循传统的数据库命名.NameOfNavigationPropertyNameOfRelatedPK 由...提供 NavigationPropertyNameForeignKeyDiscoveryConvention NameOfRelatedTypeNameOfItsPK 由...提供 TypeNameForeignKeyDiscoveryConventionNameOfRelatedPK 由...提供 PrimaryKeyNameForeignKeyDiscoveryConvention | 归档时间: |
|
| 查看次数: |
6250 次 |
| 最近记录: |