What's going on here? (LINQ to SQL/anonymous question) RRS feed

  • Question


    I've been trying to lean LINQ to SQL and I'm having a hard time figuring out how this works:


    PlanningNumbers.Single(p => p.PlanningNumber1 == pnum);


    PlanningNumbers is a LINQ representation of a table and what this does is "SELECT * from PlanningNumbers WHERE PlanningNumber1=pnum". I can't figure out for the life of me how it does this though. Here is the definition of Single():


    public static TSource Single<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate);


    and that's it, from what I can gather "this IQueryable" refers to PlanningNumbers and I assume Expression<Func<TSource,bool>> is the anonymous function "p => p.PlanningNumber1 == pnum" but I can't figure out how the code knows that "p" is a PlanningNumber object, how it generates the SQL or how I would add aditional conditions using this syntax. Any explanation or links to tutorials will be appriciated. Thanks!



    Thursday, May 8, 2008 7:31 PM

All replies