that doesnt work Mike?
did you mean:
int? foundId = context.Things.Where(t => t.ID == lookupID).Select(t => *(int?)* t.ID).SingleOrDefault();


On 26/07/2012 8:05 PM, Michael Minutillo wrote:
Try

int? foundId = context.Things.Where(t => t.ID == lookupID).Select(t => t.ID).SingleOrDefault();



Michael M. Minutillo
Indiscriminate Information Sponge
http://codermike.com


On Thu, Jul 26, 2012 at 7:26 PM, Greg Keogh <[email protected] <mailto:[email protected]>> wrote:

    I have to find an object in an EF4 entity collection with a
    specific ID property and return the int value if it’s found and
    return  (int?)null if otherwise. This skeleton code crashes of
    course if the ID isn’t found.

    int? foundId = context.Things.SingleOrDefault(t => t.ID ==
    lookupID).ID;

    So what is the best way of recoding this elegantly as a one-liner
    so it gives me the ID or null when not found? It has to be a
    one-liner because it’s in a select clause.

    Greg



Reply via email to