2014-09-06 60 views
0

我在EF 6中有此类,并且正在使用T4模板生成它的代码。如何在T4模板中找到实体框架类的关键字段

public partial class LocationState 
{ 
    public LocationState() 
    { 
    } 

    public int LocationStateID { get; set; } 
    public Nullable<int> LocationCountryID { get; set; } 
    public string Name { get; set; } 
    public string Abbreviation { get; set; } 

    public virtual LocationCountry LocationCountry { get; set;} 
} 

从T4模板中,我可以识别LocationCountry作为对象的导航属性。但是,我只想取出不是键的字段,而LocationCountryID被认为是原始类型。如何将LocationCountryID识别为关键字段? LocationCountry的Edm属性似乎没有与它们关联的关键字段。

感谢,

约翰

+0

我相信键(或KeyMembers)是实体类型,而不是属性的属性的属性。 – bricelam 2014-09-06 15:28:06

+0

谢谢bricelam,它将返回主键,而不是与类的对象成员关联的关键字段。 Visual Studio用来为EF编辑创建脚手架的向导似乎知道如何去做。 – 2014-09-06 17:03:09

回答

0

这个问题得到回答下面的文章。公平地说,我真的在发布前首先进行了搜索,但直到我进入edmx,才发现'association'标签是我想要的,我能够找到答案。希望这篇文章将成为答案的另一个入口。

Access Association Details of NavigationProperty