从两个表创建一个实体 [英] Creating one entity from two tables

查看:81
本文介绍了从两个表创建一个实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在我的数据库中,我有两个具有相同结构的表;我想要做的是将它们作为概念层中的单个实体公开。

如果考虑northwind数据库,我们将复制Products表,以便我们有OldProducts(用于存档目的)。
我可以轻松扩展SSDL,MSL和CSDL以将OldProducts表作为一个单独的实体包含在内,但我怎样才能"隐藏"旧产品实体,当我查询产品时,我将查询Products和OldProducts表的内容?
我看到的将两个表映射到单个实体的所有示例都是第二个表包含子数据的所有示例父级(例如客户的地址)

感觉自然要做的就是使用MappingFragment部分,但是我尝试过的各种组合都无法获得有效的解决方案。
< br>任何人都可以就此提供任何指导吗?它甚至可能吗?

TIA
Alan


所有事情都很难解决之前

解决方案

< blockquote> Hi *,

这是IMO,继承的典型场景。查看 http://msdn.microsoft.com/en-us/library/aa697427 (VS.80).aspx http://blogs.msdn.com/adonet/archive/2007/03/15/inheritance-in-the-entity-framework.aspx 。作为提示,您只需创建从Product派生的entityset Product和OldProduct。然后,当您查询产品时,您还将获得OldProducts(例如,您可以通过运算符区分它。)


Hi,
In my database, I have two tables that have the same structure; what I would like to do is expose these as a single entity within the conceptual layer.

If you consider the northwind database, we are duplicating the Products table so that we have OldProducts (for archive purposes).
I can easily extend the SSDL, MSL and CSDL to include the OldProducts table as a separate entity, but how can I "hide" the Old Products entity such that when I query Products I will query the contents of both the Products and OldProducts tables?
All the examples I've seen of mapping two tables into a single entity are where the second table contains child data of the parent (eg address of a customer)

It feels like the natural thing to do is to use the MappingFragment sections, however the various combinations I've tried have failed to get a working solution.

Can anyone provide any guidance on this? Is it even possible?

TIA
Alan


All things are difficult before they are easy

解决方案

Hi *,

this is, IMO, typical scenario for inheritance. Check the http://msdn.microsoft.com/en-us/library/aa697427(VS.80).aspx or http://blogs.msdn.com/adonet/archive/2007/03/15/inheritance-in-the-entity-framework.aspx. As a hint, you will just simply create entityset Product and OldProduct deriving from Product. Then, when you will query for Products, you'll get also OldProducts (and you can distinguish it by is operator, for instance).


这篇关于从两个表创建一个实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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