You could do this:

public class Product
{
   public List<Product> GetAll()
   {
       DataEntities ctx = new DataEntities();
       {
           var qry = from c in InnerQuery(ctx)
                     select c;
           return qry.ToList();
       }
   }

   public List<Product> GetAllContaining(string needle)
   {
       DataEntities ctx = new DataEntities();
       {
           var qry = from c in InnerQuery(ctx)
                     where c.Id.Contains(needle) || c.Name.Contains(needle)
                     select c;
           return qry.ToList();
       }
   }

   private IQueryable<Product> InnerQuery(DataEntities ctx)
   {
return ctx.Products.Where(c => c.DATAAREAID == "boi" && c.ITEMGROUPID ==
"fg");
   }
}

Multiple WHERE clauses are just ANDed together anyway

On Tue, Jul 13, 2010 at 3:02 PM, Arjang Assadi <[email protected]>wrote:

> Greetings,
>
> I am trying to factor out the qry from GetAll and reuse it (instead of
> copy and pasting ) in GetAllContaining(needle).
> Here is the code: (any other points is also welcomed :)
>
> public class Product
> {
>    public List<Product> GetAll()
>    {
>        DataEntities ctx = new DataEntities();
>        {
>            var qry = from c in ctx.Products
>                      where c.DATAAREAID == "boi" && c.ITEMGROUPID == "fg"
>                      select c;
>            return qry.ToList();
>        }
>    }
>
>    public List<Product> GetAllContaining(string needle)
>    {
>        DataEntities ctx = new DataEntities();
>        {
>            var qry = from c in ctx.Products
>                      where (c.DATAAREAID == "boi" && c.ITEMGROUPID == "fg")
> &&
>                      (c.Id.Contains(needle) || c.Name.Contains(needle))
>                      select c;
>            return qry.ToList();
>        }
>    }
> }
>
> Thank you
>
> Arjang
>



-- 
Michael M. Minutillo
Indiscriminate Information Sponge
Blog: http://wolfbyte-net.blogspot.com

Reply via email to