0

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;

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;

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 :))

Sergey Shulik
  • 950
  • 1
  • 9
  • 24

2 Answers2

1

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/

jeroenh
  • 26,362
  • 10
  • 73
  • 104
1

The problem here is that EF is not very well suited for "bad databases". EF (and especially all automation tools like model wizard) expects clear and correct database design.

Include is not supported in queries using custom joins or projections. Not supported in this case means that it is completely omitted.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670