EF4:NavigationProperty and join:是错误还是功能? [英] EF4: NavigationProperty and join: is a bug or a feature?
问题描述
我想咨询一下我遇到的问题.我已经开始研究一个数据库非常困难的项目:数据库中的许多表没有主键或有多个PK,因此我无法为edmx中的所有实体添加正确的关联.但是,对于某些实体来说,这是有可能的,而我设法做到了.因此,我有两个相互关联的实体:Vulner和VulnerDescription.而且我有一个针对Vulner的坏"连接表,称为VulnerObjectTie(带有心理性的FK:VulnerObjectTie.Vulner = Vulner.Id),我无法向其中添加正确的关联.因此,我决定添加以下LinqtoEntities查询:
I’d like to consult about a problem I have faced. I've started working on a project with a very difficult database: many tables in the DB don’t have primary keys or have multiple PKs, so I can't add correct associations for all entities in my edmx. However, for some entities it’s possible and I managed to do so. Thus, I have two entities with an association between them: Vulner and VulnerDescription. And I have a "bad" connection table for Vulners called VulnerObjectTie (with a mental FK: VulnerObjectTie.Vulner = Vulner.Id), which I can’t add correct associations to. So, I decided to do add the following LinqtoEntities query:
var vulerIdList = from vulner in _businessModel.DataModel.VulverSet.Include("Descriptions")
join objectVulnerTie in _businessModel.DataModel.ObjectVulnerTieSet on vulner.Id equals objectVulnerTie.Vulner
where softwareId.Contains(objectVulnerTie.SecurityObject)
select vulner;
,其中描述是与VulnerDescription表关联的导航属性.该查询有效,但不会加载Descriptions属性.但是,如果删除联接运算符,则说明将正确加载.
where description is Navigation Property for an association with the VulnerDescription table. The query works, but it does not load the Descriptions property. However, if I remove the join operator, then Descriptions are loaded correctly.
此问题最明显的解决方案是将一个查询分为接下来的两个查询:
The most obvious solution for this problem is to divide one query into the next two queries:
var vulerIdList = from vulner in _businessModel.DataModel.VulverSet
join objectVulnerTie in _businessModel.DataModel.ObjectVulnerTieSet on vulner.Id equals objectVulnerTie.Vulner
where softwareId.Contains(objectVulnerTie.SecurityObject)
select vulner.Id;
var query = from vulner in _businessModel.DataModel.VulverSet.Include("Descriptions")
where vulerIdList.Contains(vulner.Id)
select vulner;
但我认为它看起来很丑.谁能为这个问题提出一个更简单的解决方案,还是仅仅是EF4的一项特殊功能?
But I think it looks ugly. Can anyone suggest a more simple solution for this problem, or is it just a special feature of EF4??
thankyouplease:))
thankyouplease :))
推荐答案
这是已知的功能"或局限性,具体取决于您如何看待它.这是一个有关该主题的有趣讨论,我敢肯定还有更多参考可以找到:
It's a known 'feature' or limitation, depending on how you look at it. Here's an interesting discussion on the topic, I'm sure there are more references to find: http://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/thread/d700becd-fb4e-40cd-a334-9b129344edc9/
这篇关于EF4:NavigationProperty and join:是错误还是功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!