Using a Linq Query with LLBLGenProDataSource

Posts   
 
    
jbliss1234
User
Posts: 42
Joined: 04-May-2007
# Posted on: 23-Aug-2010 21:09:02   

I have a Telerik grid bound to an LLBLGEnProDatasource. I am having trouble expressing a query in LLBLGen's native filter syntax. However, I can easily express the same query in Linq.

Is it possible for me to use the Linq query with LLBLGenProDatasource and still use Livepersistence="true", and get automatic updates and inserts?

Using LLBLGen version 2.6.9.616, ASP.Net version 3.5.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 24-Aug-2010 06:24:42   

jbliss1234 wrote:

Is it possible for me to use the Linq query with LLBLGenProDatasource and still use Livepersistence="true", and get automatic updates and inserts?

No. You should use LiverPersistance=false and implement the event handlers explained here. Then in PerformSelect you should execute the linq query that returns a EntityCollection (see ILLBLGenProQuery) then assign that in to the datasource collection.

David Elizondo | LLBLGen Support Team
jbliss1234
User
Posts: 42
Joined: 04-May-2007
# Posted on: 26-Aug-2010 22:58:41   

Looks like I am missing something here.

In the PerformSelect event, e.ContainedCollection is a readonly property..Therefore, even if I were to execute a Linq query using ILLBLGenProQuery, how would I hook up the results of that query back to the datasource?

On the other hand, e.ContainedCollection.GetMulti requires a IPredicate as the Select filter which I don't have...

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 27-Aug-2010 07:13:15   

Here is an example:

protected void _customerDS_PerformSelect(object sender, SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs e)
{
    
    LinqMetaData metaData = new LinqMetaData();

    var q = from c in metaData.Customer where c.Country == "Germany" select c;
    CustomerCollection customers = ((ILLBLGenProQuery)q).Execute<CustomerCollection>();

    e.ContainedCollection.AddRange(customers);
}
David Elizondo | LLBLGen Support Team