2

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

0

1 Answer 1

6

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}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.