防止EF6生成导航属性 [英] Prevent EF6 from generate navigation properties

查看:244
本文介绍了防止EF6生成导航属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我开始使用EF6,我正在构建一些T4模板,以自动生成一些代码(在VS2012上)。



我正在生成我的模型从数据库和这个过程创建所有的关联自动基于DB ForeignKeys。并且在关联/ FK中为该字段生成导航属性。



我想要获得没有导航属性的实体的平板版本。只是一个类与表列相对应的属性。



有没有办法从数据库生成模型,得到这个?我已经尝试更新模型,并选择在模型中添加外键列,但是还没有生成关联和导航道具。



提前感谢

解决方案

解决方案



我正在阅读概念模型,我正在获得关于表格结构的无关紧要的信息,因为在edmx上的概念模型,因为当我们有外键时,创建了关联,并且Nav导师代替常规的属性(在使用FK的字段上)



我找到的解决方案是使用商店模型而不是Conceptual模型



获取概念模型错误的方式

  MetadataLoader loader = new MetadataLoader(this); 
EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);

获取商店模型GOOD方式

  MetadataLoader loader = new MetadataLoader(this); 
StoreItemCollection ItemCollection = null;
loader.TryCreateStoreItemCollection(inputFile,out ItemCollection);


I've recently started to use EF6 and i'm building a couple of T4 templates to generate some code automatically (on VS2012).

I'm generating my model from the database and this process creates all the associations automatically based on the DB ForeignKeys. And generates too a "Navigation Property" for that field in Associations/FK.

I want to get a "Flat Version" of my entities without navigation properties. Just a class with properties corresponding to table columns.

Is there any way to "Generate Model from Database" and get this? i've tried to update model with the option "Include foreign key columns in the Model" unchecked, but the associations and nav props are still being generated.

thanks in advance

解决方案

SOLUTION FOUND

As i was reading the conceptual model, i was getting innaccurated information about the table structure, because the conceptual model on the edmx, because when we have foreign keys, associations are created and Nav props instead of regular property (on the fields withing the FK).

The solution i Found is use the store model instead of Conceptual model

Getting the Conceptual Model "Wrong way"

MetadataLoader loader = new MetadataLoader(this);
EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);

Getting the Store Model "GOOD way"

MetadataLoader loader = new MetadataLoader(this);
StoreItemCollection ItemCollection = null;
loader.TryCreateStoreItemCollection(inputFile, out ItemCollection);

这篇关于防止EF6生成导航属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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