I just asked this question . Which led me to a new question :)
Until now, I used the following Linq to SQL material selection template to process the 0 "rows" returned by the query:
var person = (from p in [DataContextObject].Persons where p.PersonsID == 1 select new p).FirstOrDefault(); if (person == null) {
But I can not use FirstOrDefault() when I do this:
var person = from p in [DataContextObject].Persons where p.PersonsID == 1 select new { p.PersonsID, p.PersonsAdress, p.PersonsZipcode };
How to check for the presence of 0 "rows" returned by a query using the second pattern?
UPDATE:
I think my build failed because I'm trying to assign the result of the query to a variable ( this._user ) declared with type [DataContext].User .
this._user = (from u in [DataContextObject].Users where u.UsersID == [Int32] select new { u.UsersID }).FirstOrDefault();
Compilation error: It is not possible to implicitly convert the type "Anonymous type No. 1" to "[DataContext] .User".
Any thoughts on how I can get around this? Should I create my own object?
source share