CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

.Where Clause parameter Expression<Func<T>> or Func<T>

659 Views
Copy Code Show/Hide Line Numbers
// works as expected
public wws_Item LoadBySku(string sku)
{
    Expression< Func<wws_Item, bool> > func = itm => itm.Sku == sku;
 
    Entity = Context.wws_Items.Where(func).SingleOrDefault();
    if (Entity != null)
        OnLoaded(Entity);
 
    return this.Entity;
    // return LoadBase(func);  // works
}
 
// doesn't work (Entity is null) but compiles
public wws_Item LoadBySku(string sku)
{
    Func<wws_Item, bool> func = itm => itm.Sku == sku;
 
    Entity = Context.wws_Items.Where(func).SingleOrDefault();
    if (Entity != null)
        OnLoaded(Entity);
 
    return this.Entity;
    // return LoadBase(func);  // doesn't work
}
by Rick Strahl
  October 04, 2009 @ 5:02pm
Tags:
Description:
I guess I'm not sure why the Func<T> only parameters exist and if they ever would actually work? It seems it always requires an expression in order to run the L2S code.

Expressions only for L2S and Func<T> from LINQ to Objects?

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate