Search code examples
c#linq-to-sqlentity-relationship

Why are my manually created Linq2Sql table relationships showing up in code?


I have some views that I'd like to relate together in my Linq2Sql DBML file.

I've right clicked, selected "Add association" and manually created the associations from children to parents, for example:

Customer.TypeId -> CustomerTypes.Id

But I cannot do this in my code:

from c in Customers select c.Type.Name

Any clues? If the relationships existed in the database, which they don't and can't, then I would be able to do this.


Solution

  • This is bizarre; I remember writing the answer I came up with on here!

    Basically the problem was that because I was looking at Views as opposed to tables, and trying to relate them together in the DBML file, they obviously didn't have primary keys. Once I'd told Linq2Sql which columns were the primary keys it was a happy chappy!