0

Usually with BLToolKit I fetch data from DB in the following way:

using ( DbManager db = new MyDbManager() )
{
    IList<MyObjects> objects = db
        .SetCommand(query)//sometimes with additional parameters
        .ExecuteList<MyObjects>()
        ;
}

I would like to have ability to do the following:

using ( DbManager db = new MyDbManager() )
{
    IQueryable<MyObjects> qObjs = db
        .SetCommand(query)//sometimes with additional parameters
        .ExecuteQuery<MyObjects>()// here I don't want query actually to be executed
        ;

    // ... another logic, that could pass qObj into other part of program

    IList<MyObjects> objects = qObjs
        .Where(obj=>obj.SomeValue>=SomeLimit)    // here I want to put additional filters
        .ExecuteList()  // and only after that I wan't to execute query and fetch results
        ;
}

It is possible to workaround that with modifying orignal query-string (modify WHERE part), but sometimes it is pretty complicated.

Is there any easy way to do that?

Thanks. Any thoughts are welcome!

Budda
  • 18,015
  • 33
  • 124
  • 206

2 Answers2

2
using ( DbManager db = new MyDbManager() )
{
    IQueryable<MyObjects> qObjs = 
        from p in db.GetTable<MyObjects>()
        //sometimes with additional parameters
        select p;

    // ... another logic, that could pass qObj into other part of program

    IList<MyObjects> objects = qObjs
        .Where(obj=>obj.SomeValue>=SomeLimit)    // here I want to put additional filters
        .ToList()  // and only after that I wan't to execute query and fetch results
        ;
}
IT.
  • 859
  • 4
  • 11
0

if you want to have IQueriable , you have to use Linq. BlToolkit.Linq and BlToolkit.Data.Linq must import.

        IQueryable<DataModel.Object> query  = db.Object;


        If ((int)cmb_somthing.SelectedValue) > 0 {

            int ID  = (int)cmb_somthing.SelectedValue;
            query = query.Where(m=> m.ID = ID);

        }
        query = query.Where(m=> m.Date >= StartDate &&
                                m.Date <= EndDate);
mehdi
  • 645
  • 1
  • 9
  • 9