views:

87

answers:

1

Hi

I'm getting into LinqToSql and using the NerdDinner tutorial.

I'm trying to understand the syntax and would like to write out in more verbose fashion what is happening in the first line, which works.

Question: How can I write the first query something like the commented out code (which doesn't work).

public Dinner GetDinner(int id){

        var result = db.Dinners.SingleOrDefault(d => d.DinnerID == id);

        //var result = from d in db.Dinners.SingleOrDefault
        //             where d.DinnerID == id
        //            select d;

        return (result);
    }

Cheers

Dave

+2  A: 

Unfortunately there isn't a declarative version of SingleOrDefault that you can use. Instead, wrap your declarative LINQ statement in parentheses like so:

var result = (
              from d in db.Dinners 
              where d.DinnerID == id 
              select d
             ).SingleOrDefault();
roufamatic