如何获取实体集的商店类型
我正在尝试根据实体的商店类型(表或视图)来过滤实体。
我的测试项目中有 2 个实体,一个的源是表,另一个的源是视图。
<EntitySet Name="Test" EntityType="TestModel.Store.Test" store:Type="Tables" Schema="dbo" />
<EntitySet Name="TestView" EntityType="TestModel.Store.TestView" store:Type="Views" store:Schema="dbo" store:Name="TestView">
上面的代码示例取自模型的 edmx 文件的 SSDL 部分。
我认为 SSDL 中的 store:Type 信息是我所需要的,但我找不到使用实体框架 api 检索该值的方法。
任何帮助将不胜感激。
I'm trying to filter entities based on their store types (either table or view).
I have 2 entities in my test project, one's source is a table and the other's source is a view.
<EntitySet Name="Test" EntityType="TestModel.Store.Test" store:Type="Tables" Schema="dbo" />
<EntitySet Name="TestView" EntityType="TestModel.Store.TestView" store:Type="Views" store:Schema="dbo" store:Name="TestView">
The code sample above is taken from model's edmx file's SSDL section.
I think the store:Type information in SSDL is what i need but i couldn't find a way to retrieve that value using entity-framework api.
Any help will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过查看 SSpace 或 StoreItemCollection 来查询 SSDL 中的元数据。
即
不幸的是,这不会帮助您将类与它们来自表还是视图联系起来。 因为实体(即您在 CSpace 中编码的实体)而不是描述表形状的实体(即 SSpace 实体)位于 CSpace 中,并且为了了解实体是否来自视图或表,您需要能够通过映射从CSpace EntitySet到SSpace EntitySet。
不幸的是,EF 没有公开公共 CSSPace(即无法使用 API 读取 EDMX 的 MSL 片段)。
因此,为了做到这一点,您必须手动推理 MSL 元素,可能使用 LINQ to XML 等。
希望这对
亚历克斯有帮助
Well you can query the metadata in the SSDL by looking in the SSpace or the StoreItemCollection.
i.e.
Unfortunately this isn't going to help you tie your classes to whether they come from a table or a view. Because the Entities (i.e. the ones you code against in CSpace) rather than the ones that describe the shapes of the table (i.e. SSpace ones) are in CSpace and in order to know whether an Entity comes from a view or table, you would need to be able to get from the CSpace EntitySet to SSpace EntitySet via the Mapping.
Unfortunately the EF doesn't expose public CSSPace (i.e. there is no way to use the API to read the MSL fragment of the EDMX).
So in order to do this you would have to manually reason over the MSL element, probably using LINQ to XML or something.
Hope this helps
Alex