有没有办法检索实体的元数据?例如。实体密钥或StoreGeneratedPattern? [英] Is there way to retrieve the meta-data for an Entity? Eg. the Entity Key or StoreGeneratedPattern ?

查看:62
本文介绍了有没有办法检索实体的元数据?例如。实体密钥或StoreGeneratedPattern?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨大家好,

有什么方法可以编程确定实体是否有EntityKey = true或storeGeneratedPattern是什么..对于实体中的每个属性?

is there any way I could programatically figure out if an Entity has an EntityKey = true or what the storeGeneratedPattern is .. for each property in an entity?

不幸的是,我的实体类型未知(即它的类型为'T')..所以我希望只是遍历模型。实体< T> .Properties() .All()类型的东西..对于'T'实体中的每个属性,我会检查EntityKey
和/或StoreGeneratedPattern的值。

Unforunately, my entity type is unknown (ie. it's of type 'T') .. so i was hoping to just iterate through the model.Entity<T>.Properties().All() type of thing .. and for each property in the 'T' entity, I would then check the values for the EntityKey and or StoreGeneratedPattern.

这是可能吗?

推荐答案

是的,您可以从底层对象上下文中获取MetadataWorkspace; ((IObjectContextAdapter)ctx).ObjectContext.MetadataWorkspace

Yes, you can get hold of the MetadataWorkspace from the underlying object context; ((IObjectContextAdapter)ctx).ObjectContext.MetadataWorkspace

这是一篇文章,讨论从MetadataWorkspace获取实体类型的主键成员;  http://blog.cincura.net/230583-metadataworkspace-in-entity-framework/

Here is a post that talks about getting the primary key members for an entity type from the MetadataWorkspace; http://blog.cincura.net/230583-metadataworkspace-in-entity-framework/

~Rowan


这篇关于有没有办法检索实体的元数据?例如。实体密钥或StoreGeneratedPattern?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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