Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Similar expression to "Coalesce" in Entity Framework

What is the similar query to below code in entity framework c#.

SELECT StudentId,Coalesce(s.FName + ' ' + s.MName + ' ' + s.LName,
    s.FName + ' ' + s.MName,
    s.FName) AS FullName
FROM Student s
WHERE s.StudentId = 'S101';

Thanks in advance.

like image 637
Daybreaker Avatar asked Mar 25 '14 09:03

Daybreaker


People also ask

What is Coalesce expression in c#?

CsharpProgrammingServer Side Programming. The null coalescing operator is used with the nullable value types and reference types. It is used for converting an operand to the type of another nullable (or not) value type operand, where an implicit conversion is possible.

What is a coalesce expression?

Coalesce(Expression, Expression, LambdaExpression) Creates a BinaryExpression that represents a coalescing operation, given a conversion function. Coalesce(Expression, Expression) Creates a BinaryExpression that represents a coalescing operation.


1 Answers

Have a look at null-coalescing operator

e.g.

string text1 = null;
string result = text1 == null ? "default" : text1 ;

you can do

string result = text1 ?? "default";
like image 50
huMpty duMpty Avatar answered Sep 23 '22 09:09

huMpty duMpty