2

如何在 linq 中选择 NULL 作为列选项。

我的 sql 会读取。

Select field1, field2, field3, null as "null", field4 
from table1

我的 linq 查询将是:

from t in table1
select new { t.field1, t.field2, t.field3, null as "null", t.field4}

视觉工作室产生的错误是:

无法分配给匿名类型属性

4

1 回答 1

6

删除as "null"并命名参数,将其转换null为它的类型:

from t in table1
select new { t.field1, t.field2, t.field3, someField = (string)null, t.field4}
于 2013-06-21T12:56:16.170 回答