LINQ to SQL:连接表时如何处理模棱两可的列名? [英] LINQ to SQL: How to handle ambiguous column names when joining tables?

查看:130
本文介绍了LINQ to SQL:连接表时如何处理模棱两可的列名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将用上一个我问过的问题来引导这个问题:
LINQ to SQL:在多个列上进行多个联接.这可能吗?

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

所以我有一个LINQ查询:

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'

我该如何解决?

推荐答案

显式命名匿名类型的属性

With explicit naming of the properties of the anonymous type

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

这篇关于LINQ to SQL:连接表时如何处理模棱两可的列名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆