簡體   English   中英

我如何在C#中使用LINQ“選擇null作為”列”

[英]How do I “select null as ”Column" Using LINQ in C#

如何在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生成的錯誤是:

無法分配給匿名類型屬性

刪除as "null"並命名參數,將null強制轉換為其類型:

from t in table1
select new { t.field1, t.field2, t.field3, someField = (string)null, t.field4}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM