User1 User1 - 1 month ago 19
C# Question

LINQ: Where on select result?

Is it somehow possible to use variant abc without having to call Convert twice ? I mean like def, but without a second from ?

Something like:

var desired = (from x in AnswerRecords
select Converter(x) as bla
where bla != null
).ToList();

Answer

Your case fits exactly the use of the let keyword. Check SO Documentation: Defining a variable inside a Linq query (let keyword)

Use it to store the result of the Converter and then check it:

var result = from item in AnswerRecords
             let converted = Converter(item)
             where converted != null
             select converted;
Comments