How to get first EntityKey Name for an Entity in EF4

后端 未结 4 1262
死守一世寂寞
死守一世寂寞 2021-02-06 15:21

How can I get the 1st EntityKey name for an Entity for Entity Framework 4 because I\'m building a repository system and I wanted to get an item by Id (which is the primary key o

4条回答
  •  盖世英雄少女心
    2021-02-06 16:02

    You can get the Entity Key members collection from MetaDataWorkspace using the following code:

    ReadOnlyCollection keyMembers = db.MetadataWorkspace.GetType("", "Entity_Namespace", System.Data.Metadata.Edm.DataSpace.CSpace).MetadataProperties["KeyMembers"].Value as ReadOnlyCollection;

提交回复
热议问题