实体框架代码优先默认命名约定列表 [英] List of Entity Framework Code First Default Naming Conventions

查看:76
本文介绍了实体框架代码优先默认命名约定列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查找Entity Framework默认命名约定示例列表。我收集到表是< Entity> + s 例如用户...外键是User_Id,但是我想查看所有开箱即用的约定的列表-IE什么实体框架将调用我的对象。

I'm trying to find a list of examples of Entity Framework's default naming conventions. I gather that Tables are <Entity>+s e.g. Users... Foreign Keys are User_Id But I would like to see a list of all out-of-the box conventions - IE what entity framework is going to call my objects.

我不是要查找约定的类型-我明白了。我正在寻找Entity Framework的默认约定命名数据库对象的定义/示例。需要明确的是,我没有添加或删除任何约定。 EF带有许多用于生成数据库对象的默认约定-我想知道EF的现成默认约定将如何命名我的数据库对象。

I'm not looking for the types of the conventions - I got that. I am looking for definitions/examples of what Entity Framework's default conventions will name my database objects. To be clear, I have not added or removed any conventions. EF comes with a number of default conventions for generating databse objects - I want to know what EF's out-of-the box default conventions are going to name my database objects.

我之所以需要这样做,是因为尽管我使用的是CodeFirst,但我将手动创建数据库对象,而不是让EntityFramework为我生成它(我的同事坚持这样做)。因此,我需要知道我应该如何命名表,列,外键……,以便实体框架无需显式映射即可查找/映射它们。

The reason I require this is because although I am using CodeFirst, I will be creating my database objects by hand rather than making EntityFramework generate it for me (my colleague is insisting on this). Therefore I need to know what I should name my Tables, Columns, Foreign Keys...... So that Entity Framework will find/map them with no explicit mappings required.

例如

EF Default TableName Convention
      <Entity> + 's' (e.g ***Users***) 

EF Default Foreign Key Convention
      <Entity> + 'Id' (e.g ***UserId***)   

EF Default Primary Key Convention
      ***Id***  

在哪里可以找到这个?

推荐答案

EF可以没有提供检索使用的约定集的机制。您只能删除预先配置的约定

EF does not provide a mechanism to retrieve the set of conventions used. You can only remove pre configured conventions.

您可以在 MSDN

最初,EF允许您自定义约定,但现在该部分已从API中删除。

Initially EF allowed you to customize the conventions but now that part is removed from API.

编辑

Convention: Table Name
Default: Entity + s (e.g Users)

PluralizingTableNameConvention

Convention: Foreign Key Relation
Default: Entity + Id (e.g UserId)

NavigationPropertyNameForeignKeyDiscoveryConvention

Convention: Primary Key
Default: Id

IdKeyDiscoveryConvention

这篇关于实体框架代码优先默认命名约定列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆