LINQ to SQL: How to handle ambiguous column names when joining tables?

僤鯓⒐⒋嵵緔 提交于 2019-12-21 19:24:39

问题


I'm going to bootstrap this question with a previous one I asked:
LINQ to SQL: Multiple joins ON multiple Columns. Is this possible?

So I have a LINQ query:

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'

How can I resolve this?


回答1:


With explicit naming of the properties of the anonymous type

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


来源:https://stackoverflow.com/questions/5309507/linq-to-sql-how-to-handle-ambiguous-column-names-when-joining-tables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!