LINQ to SQL:如何在连接表时处理不明确的列名?

时间:2011-03-15 09:04:13

标签: c# linq-to-sql anonymous-types ambiguity

我要用前一个问题引导这个问题我问: LINQ to SQL: Multiple joins ON multiple Columns. Is this possible?

所以我有一个LINQ查询:

var query =
    from t1 in myTABLE1List // List<TABLE_1>
    join t2 in myTABLE1List
      on new { t1.ColumnA, t1.ColumnB } equals new { t2.ColumnA, t2.ColumnB }
    join t3 in myTABLE1List
      on new { t2.ColumnA, t2.ColumnB } equals new { t3.ColumnA, t3.ColumnB }
  select new {t1.ColumnA, t2.ColumnA, t3.ColumnA } // Duplicate Anon type 'ColumnA'

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:7)

明确命名匿名类型的属性

select new {t1A = t1.ColumnA, t2A = t2.ColumnA, t3A = t3.ColumnA }