Question about replacing predicate expressions on a delete

Posts   
 
    
SeanS
User
Posts: 14
Joined: 07-Jun-2008
# Posted on: 13-Jun-2008 14:58:09   

Say I have this:

PageGroupCollection pageGroupLinkList; PredicateExpression idSearchExpression;

pageGroupLinkList = new PageGroupLinkList(); idSearchExpression = new PredicateExpression(PageGroupFields.PageID == neededID); pageGroupLinkList.DeleteMulti(idSearchExpression);

Is there a way to convert this over to the new linq system in 2.6? I was kind of hoping DeleteMulti would except lambda expressions like say linqMetaData.SomeClass.Count.

I was also thinking maybe its something like:

var query = from pageGroup in linqMetaData.PageGroup where pageGroup.ID == neededID select pageGroup;

then use something like DeleteMulti(query). Is there someway to do this?

Sean

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39872
Joined: 17-Aug-2003
# Posted on: 13-Jun-2008 17:00:48   

Sorry, that's not possible. Linq is a fetching technique with everything to fetch the query build in. It can't be used to specify a 'filter', it's a complete query + engine to fetch itself.

A lambda is just a lambda, it can't be translated to a predicate without more context, but that would require a complete query.

Frans Bouma | Lead developer LLBLGen Pro
SeanS
User
Posts: 14
Joined: 07-Jun-2008
# Posted on: 13-Jun-2008 17:25:45   

Otis wrote:

Sorry, that's not possible. Linq is a fetching technique with everything to fetch the query build in. It can't be used to specify a 'filter', it's a complete query + engine to fetch itself.

A lambda is just a lambda, it can't be translated to a predicate without more context, but that would require a complete query.

Maybe I misunderstood something then, and this becomes a different question

Take:

linqHandler.User.Count(currentUser => currentUser.LoginName = "hihihi");

How is that working? Normally for a collection that is the same as say:

userCollection.Count(delegate(User currentUser){ stuff here; });

But this would assume that userCollection is already filled. Is the linqHandler grabbing everything from the table, then applying the count as opposed to a SELECT Count() query?

As for the original post, I guess on that point I was hoping something could take in the query and use it to delete rather than select from a table.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39872
Joined: 17-Aug-2003
# Posted on: 14-Jun-2008 12:54:41   

SeanS wrote:

Otis wrote:

Sorry, that's not possible. Linq is a fetching technique with everything to fetch the query build in. It can't be used to specify a 'filter', it's a complete query + engine to fetch itself.

A lambda is just a lambda, it can't be translated to a predicate without more context, but that would require a complete query.

Maybe I misunderstood something then, and this becomes a different question

Take:

linqHandler.User.Count(currentUser => currentUser.LoginName = "hihihi");

How is that working? Normally for a collection that is the same as say:

userCollection.Count(delegate(User currentUser){ stuff here; });

But this would assume that userCollection is already filled. Is the linqHandler grabbing everything from the table, then applying the count as opposed to a SELECT Count() query?

The compiler will either: 1) create code to produce a delegate at runtime or 2) create code to produce an expression tree at runtime.

Only the second can be interpreted and converted into a db query. The compiler only does 2 if the source is an IQueryable. If the source is an IEnumerable, it will go for option 1.

So in this case, it can't be option 2, as it first has to specify a source which is IQueryable, but you're referring to something which is in-memory, thus an IEnumerable.

Frans Bouma | Lead developer LLBLGen Pro
SeanS
User
Posts: 14
Joined: 07-Jun-2008
# Posted on: 16-Jun-2008 15:41:22   

Otis wrote:

The compiler will either: 1) create code to produce a delegate at runtime or 2) create code to produce an expression tree at runtime.

Only the second can be interpreted and converted into a db query. The compiler only does 2 if the source is an IQueryable. If the source is an IEnumerable, it will go for option 1.

So in this case, it can't be option 2, as it first has to specify a source which is IQueryable, but you're referring to something which is in-memory, thus an IEnumerable.

So basically, if I am understanding this:

linqHandler.User.Count(currentUser => currentUser.LoginName = "hihihi");

Will go ahead and fill the collection with every user then apply the expression to the created IEnumerable?

Sorry if these are plainly obvious answers.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39872
Joined: 17-Aug-2003
# Posted on: 16-Jun-2008 16:05:14   

SeanS wrote:

Otis wrote:

The compiler will either: 1) create code to produce a delegate at runtime or 2) create code to produce an expression tree at runtime.

Only the second can be interpreted and converted into a db query. The compiler only does 2 if the source is an IQueryable. If the source is an IEnumerable, it will go for option 1.

So in this case, it can't be option 2, as it first has to specify a source which is IQueryable, but you're referring to something which is in-memory, thus an IEnumerable.

So basically, if I am understanding this:

linqHandler.User.Count(currentUser => currentUser.LoginName = "hihihi");

Will go ahead and fill the collection with every user then apply the expression to the created IEnumerable?

Sorry if these are plainly obvious answers.

It depends on what 'linqHandler' is. If it's a LinqMetaData instance, it will produce a db query, because linqHandler.User would be an IQueryable. simple_smile So in your example above, what's linqHandler?

Frans Bouma | Lead developer LLBLGen Pro
SeanS
User
Posts: 14
Joined: 07-Jun-2008
# Posted on: 16-Jun-2008 16:51:25   

Otis wrote:

SeanS wrote:

Otis wrote:

The compiler will either: 1) create code to produce a delegate at runtime or 2) create code to produce an expression tree at runtime.

Only the second can be interpreted and converted into a db query. The compiler only does 2 if the source is an IQueryable. If the source is an IEnumerable, it will go for option 1.

So in this case, it can't be option 2, as it first has to specify a source which is IQueryable, but you're referring to something which is in-memory, thus an IEnumerable.

So basically, if I am understanding this:

linqHandler.User.Count(currentUser => currentUser.LoginName = "hihihi");

Will go ahead and fill the collection with every user then apply the expression to the created IEnumerable?

Sorry if these are plainly obvious answers.

It depends on what 'linqHandler' is. If it's a LinqMetaData instance, it will produce a db query, because linqHandler.User would be an IQueryable. simple_smile So in your example above, what's linqHandler?

Oh my bad, it's a LinqMetaData. I get it now. Sorry a little slow.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39872
Joined: 17-Aug-2003
# Posted on: 16-Jun-2008 18:27:38   

No worries, it's not really clear from Linq's design what will be done:

var q = from u in o.User where u.Name=="John" select u;

what's done? a db query? in-memory query? Unclear.

Frans Bouma | Lead developer LLBLGen Pro