Linq To SQL Without Explicit Foreign Key Relationships

前端 未结 7 1518
陌清茗
陌清茗 2020-12-16 14:54

I am working with a few legacy tables that have relationships, but those relationships haven\'t been explicitly set as primary/foreign keys. I created a .dbml file using \"

7条回答
  •  借酒劲吻你
    2020-12-16 15:26

    Your query looks correct and should return a query result set of Case objects.

    So... what's the problem?

    (Edit) My problem being that CaseInfo is not available under Cases... i.e. c.CaseInfo doesn't exist where I'm assuming it would be if there were explicit primary/foreign key relationships.

    What do you mean by "not available"? If you created the association in the designer as you say you did, then the query should generate SQL something along the lines of

    SELECT [columns] 
    FROM Case INNER JOIN CaseInfo 
       ON Case.CaseID = CaseInfo.CaseID
    WHERE CaseInfo.CaseInfoMeta = 'some value'
    

    Have you debugged your linq query to get the SQL generated yet? What does it return?

提交回复
热议问题