views:

83

answers:

2

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.

A: 

I just tried the same thing and the query was only possible once I had rebuilt the solution that contained the linq-to-sql dbml file. Have you rebuilt the solution after making the change to the relationships?

This was done using two tables though, let me link up two views and I'll edit this answer with the results

EDIT: Ok that sucks, putting an assosiation on a LinqToSql query thats only queries views in the database doesn't work. You can however specify an join in your linq query. Sadly it is like doing double work specifing it on the DBML file and in your code but if you just put some comments there people will understand why you did it.

So at least on the DBML file that "join" is visible to others.

FailBoy
+1  A: 

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!

joshcomley