This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi guys! I have the problem with writing LINQ extension method with LightSpeed entities collection. Assume we have the following model: And I want to have an extension method for IQueryable
And so on, just to specify property selector for the field containing branch ID. So, I've written this:
But here I'm getting "This expression type is not supported in LightSpeed 4.0" error. Note, that I'm using LS 5.0 from 03/23/2015 nightly. Why it tells me that it's not supported in LS 4.0?) I believe it's just an old value in error message string and can be changed too. But the main question is how can I reach my goal? Is it possible to have such operations in the LightSpeed LINQ? |
|
|
OMG, I've forgotten that I asked it already) http://www.mindscapehq.com/forums/thread/2177242 But it's still make me pain - why can't it be implemented from your side?
You need just to implement support for property selectors (Func |
|
|
OK. I'm trying to reach this from other side. The model is the same. Lets write an interface highlighting Branch ID field:
And let's implement it for the partial db model class:
And let's write the following extension for the IQuaryable collection:
But this code still failed with an error:
And here is the stack trace:
Is it possible to make this kind of solution make work? Any thoughts? Thanks in advance! |
|
|
Without the project to reproduce this the use of this client side code stands out as possibly being the issue:
What does that property do?
|
|
|
It's just getting a List of Int32 containing available Branch IDs for current user. I've created an example project with three my attempts of such filter implementation and all failed:
Could you please help me to reach my final goal? I want to have an extension method filtering my entities by branch (i.e. get only those terminals, merchants, etc which belongs to the branches only available for user). |
|
|
Thanks for the repro project. The issue is due to trying to translate the predicate passed to your BranchFilter method as it is seen as a method invocation which we dont support. Did you try:
to cover the initial query?
|
|
|
Thanks for your reply. Yes, I've already tried the code you recommended. It works but looks unpleasant. =) I finally managed to find a working solution. Here is it:
The key moment was in proper combining two lambdas into one. I was wrong trying to do it with Expression.Invoke method. The right way was in using the Body of property selector (as it shown in the code). But for the future you may implement ExpressionType.Invoke in your linq provider. for example you may evaluate it as a subquery and use this result in the main query. |
|