Using Linq to Sql, how can I get a specific result from a query?

I want to get the latest result returned from this request. How should I do it? Last and LastOrDefault are not supported by Linq to Sql.

 var docs = (from d in db.Documents                      
                    where d.Version > 1
                    orderby d.DocumentID
                    select new   
                               {                                     
                                   d.DocumentID,
                                   d.DocTypeID,
                                   d.Name,
                                   d.Version
                               });

      

+1


source to share


1 answer


Cancel the sort criteria (add descending

) and use First

(or FirstOrDefault

if necessary).



+4


source







All Articles