You need to put that part of the projection earlier, which is easy with a let
clause:
var name = from x in db.authors
let fullName = x.name + " " + x.surname
where fullName == "Jean Paul Olvera"
orderby x.surname
select new { x.id_author, fullName };
Note that x.name + " " + x.surname
will be compiled to the same code as String.Concat(x.name, " ", x.surname)
, but is more readable to most people. Also note that as you're not doing anything outside the ()
parentheses, there's no need for them.
I would hope that any good SQL LINQ provider should turn this query into a sensible and efficient SQL query, but you should validate this yourself. On the other hand, I would generally suggest preferring querying over individual fields, e.g.
where x.name == "Jean Paul" && x.surname == "Olvera"