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

Reply via email to