【发布时间】:2014-03-28 06:30:00
【问题描述】:
假设有一个超过 20 列的表:(col1, col2, ... )
如果我想显示col1 和col2 的总和以及其他列,
在 SQL 中我可以:
SELECT (col1+col2), * FROM table1;
但在 LINQ 中,我必须这样做
from tb in table1
select new
{
sum = tb.col1 + tb.col2,
col1 = tb.col1,
col2 = tb.col2,
...
};
还有其他更简单的方法吗?谢谢。
【问题讨论】:
-
谢谢,但我没有使用 where 过滤结果。我在 LINQ 中找到了类似的东西:select new { sum = tb.col1 + tb.col2, tb.* }
标签: c# linq linq-to-sql