简体   繁体   English

从数据库生成模型时更改EF实体命名模式

[英]Change EF Entity naming pattern when generating model from database

Is there a way to change the pattern that EF uses to generate the Entity name when generating the EDM model from an existing database? 从现有数据库生成EDM模型时,是否可以更改EF用于生成实体名称的模式?

Example: 例:

I have a table: table_name and I want my entity to be named TableName without me having to change it manually. 我有一个表:table_name,我希望将我的实体命名为TableName,而不必手动更改它。

EDIT: I know I can change the POCO generation template, but how about the EDM generation? 编辑:我知道我可以更改POCO生成模板,但是EDM生成怎么样? Is this done with a template as well? 这也可以通过模板来完成吗? If so, where is this template located? 如果是这样,此模板在哪里?

I'm affraid it is not possible - at least not without investigating possibilities of EF Designer extensibility or investigating EdmGen internals. 我认为这是不可能的-至少在没有调查EF Designer可扩展性或调查EdmGen内部情况的情况下是不可能的。 The point of Entity designer is to allow you easily map / change those names. 实体设计器的要点是允许您轻松映射/更改这些名称。

Interestingly it is possible if you start with model (EF designer) and want to generate database from the model - in such case the process is controlled by workflow and T4 templates and you can change it but in case of generating model from database the process is most probably hardcoded inside Edmgen tool - you can check if this tool has any API which would allow you changing the behavior. 有趣的是,如果您从模型(EF设计器)开始并希望从模型生成数据库,则是可能的-在这种情况下,该过程由工作流和T4模板控制,您可以更改它,但是在从数据库生成模型的情况下,该过程是最有可能在Edmgen工具内部进行了硬编码-您可以检查此工具是否具有允许您更改行为的API。

Anyway EDMX is just XML so if you have exact pattern you need to replace you can create very simple tool, transformation or script which will modify your EDMX file after generation from the database. 无论如何,EDMX只是XML,因此,如果您有确切的模式需要替换,则可以创建非常简单的工具,转换或脚本,这些工具,转换或脚本将从数据库生成后修改您的EDMX文件。

You cannot change the POCO T4 template. 您无法更改POCO T4模板。 The template must produce classes with exactly same names as you have for entities in your model. 模板必须产生与您模型中的实体名称完全相同的类。 Otherwise the POCO magic will not work. 否则POCO魔术将无法使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从实体框架模型生成数据库 - Generating database from entity framework model 从EF中的模型生成数据库时,还有另一种方式来维护计算列吗? - Is there another way to maintain computed columns when generating database from model in EF? 当我从现有数据库创建模型时,Entity Framework 4.0 生成只读模型 - Entity Framework 4.0 generating read only model when I create model from existing database 在VS 2015和EF7上从模型生成SQLite数据库 - Generating SQLite Database from Model at VS 2015 & EF7 尝试从EF实体模型生成MySQL数据库时出错 - Error while trying to generate MySQL Database from EF entity model MVC EF正确对代码进行分层,以及从数据库更新模型时如何修复导航命名 - MVC EF layering the code correctly and how to fix navigation naming when updating models from database 从模型生成数据库文件(sdf)时发生错误 - Error occurred when generating database file (sdf) from model 在运行时更改实体模型数据库 - Change Entity model database at runtime ADO.Net实体模型“来自数据库的EF Desinger”被忽略1列 - ADO.Net Entity Model “EF Desinger from Database” ignored 1 column ASP.NET MVC2和Entity Framework 4从数据库生成模型,而无需复制成员资格模型 - ASP.NET MVC2 and Entity Framework 4 Generating Model from Database without duplicating Membership Models
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM