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, I have build the following query: IQueryable<WG> query = uow.WGs.Where(w => !w.WGH.IsFlag); It is not very nice, but automatically generated. The model has the following entities: LoC, Lo, WGH, WG and the following 1..n associations: WGH -> WGs Lo1 (Lo) -> WGH1s (WGH) Lo2 (Lo) -> WGH2s (WGH) Lo -> LoCs The resulting SQL is as follows: SELECT DISTINCT The problem can be found in the bold part. As t0 is a WG and q1 is a Loc "t0.Id = q1.Id" cannot work. There is a workaround: IQueryable<WG> query = uow.WGs.Where(w => !w.WGH.IsFlag); will result in the following correct sql: SELECT DISTINCT |
|
|
Hi Dennis, Thanks for the description, I have been able to replicate the behavior you are seeing. The reason this is happening is that because the original query has a .Where clause it is treated as a subquery. With subqueries we look to see if there is a natural association between the entity type in the outer query and the entity type in the inner query, if none is found then it falls back to an Id = Id comparison (generally this would occur when you are nesting a query on the same entity). The second query works because the criteria is translated as part of the Any operator directly so it isnt treated as a subquery. We will have a think about how to tackle this one, unfortunately it is not going to be a simple fix so I will have to let you know once we have an update for this. I presume when you have said that the query is being auto-generated that this is coming from a component you are using? So you are unable to use the syntax you have described for the second query as a workaround for now?
Jeremy |
|
|
Fortunatly it is our own component and I have changed the creation as described. But we have used queries like this in further parts of the code and it is very difficult to identify every location, as this problem only occurs on concatenated queries. |
|
|
Hi, as you have published LightSpeed 4 now, we are evaluating a switch to the new version. Will the bug be fixed there? Regards, Dennis |
|
|
Hi Dennis, We would be intending to make this update on 3.x which would then be patched forward into 4. So you wouldnt need to specifically upgrade for this.
Jeremy |
|