如何在 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}
Visual Studio生成的错误是:
Cannot assign to anonymous type property
最佳答案
将删除为“null”
并命名参数,将null
转换为其类型:
from t in table1
select new { t.field1, t.field2, t.field3, someField = (string)null, t.field4}
关于c# - 如何在 C# 中使用 LINQ "select null as "列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17235734/