Read foreign key metadata programatically with Entity Framework 4

前端 未结 2 962
醉酒成梦
醉酒成梦 2020-12-03 00:21

Does anyone know how one goes about obtaining the schema information out of an edmx generated Entity Framework?

Specifically I want to manage to traverse the foreign

2条回答
  •  抹茶落季
    2020-12-03 00:37

    You can use the following approach --

    foreach (EntityType entity in ItemCollection.GetItems().OrderBy(e => e.Name))
    foreach (var entityMember in entity.NavigationProperties)
    foreach (System.Data.Metadata.Edm.EdmProperty foreignKey in entityMember.GetDependentProperties())
    {
        //... use foreignKey
    }
    

提交回复
热议问题