vwdewaal
vwdewaal

Reputation: 1005

How do I "select null as "Column" Using LINQ in C#

How do I select NULL as a column option in linq.

My sql would read.

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

My linq query would be:

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

The error generated by visual studio is:

Cannot assign to anonymous type property

Upvotes: 2

Views: 1110

Answers (1)

Oded
Oded

Reputation: 499002

Drop the as "null" and name the parameter, casting the null to its type:

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

Upvotes: 6

Related Questions