LINQ to create a calculated value based on the value of two other columns

Simplified scenario:

I want to create a calculated string property based on the value of two properties, Field1 and Field2. When Field1 has a value, Field2 is null, and viceversa. They can't be both null.

Let's call the calculated value "cv". The rule is: If Field1 is null, cv = Field2, and if Field2 is null, cv = Field1.

How can I achieve this using LINQ to Entities?



Will something like this work for you?

 context.People.Select(p => new {cv = p.DisplayName ?? p.RealName});

Need Your Help

How to set Progress bar on Message Box

c# .net winforms messagebox

I want to set progress bar on my message box how to set ...progress bar property style have Marquee property.....

Implementing application logic on model layer (MVC) model-view-controller

I keep reading that the biggest layer in the MVC pattern should be the model. I've also heard that we should avoid putting logic on the controller layer. However, as my ASP.Net MVC 5 application is