Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq to SQL - "This member is defined more than once" error

I have the following linq code...

CMSDataContext dc = new CMSDataContext();

var q = from u in dc.CMSUsers 
        join d in dc.tblDistricts
          on u.DistrictCode equals d.District into orders
        select u;     

District shows this error: Ambiguity between 'tblDistrict.District' and 'tblDistrict.District'

Any ideas?

EDIT:

It turns out that I had the same table in two different dbml files. Apparently, I cannot do this. I will have to end up joining a table from one dbml file with another table from a different dbml file. If anyone can enlighten me on how to do this, I will deem it as an answer. Thanks.

like image 977
jinsungy Avatar asked Dec 12 '08 15:12

jinsungy


2 Answers

I had he same problem. The solution was to delete .dbml file from the solution explorer.

like image 37
gkiko Avatar answered Oct 23 '22 10:10

gkiko


If you have a FK releationship between two tables, LINQ-to-SQl will automatically create a property for it.

For example, if you Order object has a CustomerID which is a Foriegn key to the Customers table, Order will automatically have a Customer property. If you already have a Customer property, there will be a conflict.

like image 84
James Curran Avatar answered Oct 23 '22 11:10

James Curran