c# - 如何在 C# 中使用 LINQ "select null as "列

标签 c# sql linq

如何在 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/

相关文章:

mysql - 从消息线程中获取嵌套的未读消息

mysql - 查找供应每个零件的供应商的供应商编号

c# - 在 LINQ OrderBY 中排除一个值

C# LINQ 选择具有多个值的属性的列表

c# - 如何在 List<T>.BinarySearch 中有效地复制 ArrayList.BinarySearch?

c# - 在 C# 中将具有变量名称/值对的 JSON 反序列化为对象

c# - 使用 Selenium WebDriver C# 在下拉列表中选择每个选项

c# - 为什么这些对象没有被处理掉

java - hibernate 中的createSQLQuery使用Prepared Statement?

c# - Linq to XML 搜索