Domanda

Di solito con BLToolKit ho recuperare i dati da DB nel seguente modo:

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

Mi piacerebbe avere la capacità di eseguire le seguenti operazioni:

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
        ;
}

E 'possibile soluzione che con la modifica orignal query string (modificare dove una parte), ma a volte è piuttosto complicato.

C'è un modo semplice per farlo?

Grazie. Tutti i pensieri sono i benvenuti!

È stato utile?

Soluzione

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
        ;
}

Altri suggerimenti

se si desidera avere IQueriable, è necessario utilizzare LINQ. BlToolkit.Linq e BlToolkit.Data.Linq devono importare.

        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);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top