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 am doing a search on two tables, depending upon the criteria passed in determins the search i'm doing. Iam doing a left outter join first and then using LAMBDA to query the query, it says lightspeed does not support this, i find that really hard to believe lightspeped dows not support a where statement, any help? var query = from m in uow.CollateralMasters join a in uow.Addresses on m.PropertyAddressSequence1 equals a.Id into x from y in x.DefaultIfEmpty() select new { Masters = m, Addresses = y };
query = query.Where(m => (!string.IsNullOrEmpty(criteria.Status)) ? m.Masters.CollateralStatusId == criteria.Status : true); ....more where statements .OrderBy(m => m.Masters.CollateralMaster_Id).Skip(0).Take(200);
list = query.ToList().ConvertAll(item => (ICollateralMaster) item.Masters);
|
|
|
Don't know if you guys had looked that his but i figured out a work around: for some reason LightSpeed does not like this: query = query.Where(m => (!string.IsNullOrEmpty(criteria.Status)) ? m.Masters.CollateralStatusId == criteria.Status : true); instead i have to do:
if (!string.IsNullOrEmpty(criteria.Status)) query = query.Where(m => m.Masters.CollateralStatusId == criteria.Status); Do u know why? Obviously i don't want to write an if statement if i don't have to (even thought there essentually the same statement
I have however run into a secondary problem in that for some reason I can't Skip and Take, I only want to retreive the first x amount of results. Thanks Again for your help, Josh |
|
|
Yes, it's a limitation with conditional (?:) expressions after an intermediate select (your select { Masters = ..., Addresses = ...} line). We support conditional expressions in normal where clauses, but it looks like we don't currently handle them after an intermediate select. We'll take a look and see if we can get you a fix. (Though personally I think the 'if' form is clearer in this particular case.) |
|
|
There will be a partial fix in the next nightly build. It should suffice for the example you provide, but it has the limitation that the condition must not depend on the lambda parameter. That is, .Where(m => !String.IsNullOrEmpty(someString) ? ... : ...) will work but .Where(m => !String.IsNullOrEmpty(m.SomeProperty) ? ... : ...) is still not supported. |
|
|
Thanks again for your help Ivan, your a superstar!!! Did you have any explanations on the Take()?
Josh |
|
|
Just realised I did not paste any code, at the end of my where statements I am doing the following:
query = query.Take(200); list = query.ToList().ConvertAll(item => (ICollateralMaster) item.Masters) |
|
|
Could you post the repro code for the Take() issue? Thanks! |
|
|
Crossed in the post there! I've tried putting a Skip and Take onto the query, and it's working fine for me. Best thing to do is try it with the next nightly (with the conditional expression fix) and see if you still get the problem with Take. If so, re-post the specific query and the error you're seeing, and we'll take another look. |
|
|
Hmmm odd, i get the following error:
at ..(IList`1 , IList`1 ) at ..(List`1 , Query , String , IdentifierExpression ) at ..(List`1 , Query , EntityTuple ) at ..(Query , EntityTuple ) at Mindscape.LightSpeed.UnitOfWork.FindGroup(Query query, EntityTuple results) at Mindscape.LightSpeed.UnitOfWorkBase.Find(Query query, EntityMap typeMap) at Mindscape.LightSpeed.Linq.Plan.SingleQueryPlan.ExecuteImmediate(IUnitOfWork unitOfWork, Type returnType) at Mindscape.LightSpeed.Linq.LinqQueryProvider.Execute(Expression expression) at Mindscape.LightSpeed.Linq.LinqQueryProvider.System.Linq.IQueryProvider.Execute(Expression expression) at Mindscape.LightSpeed.Linq.LinqQuery`1.GetEnumerator() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList(IEnumerable`1 source) |
|
|
Hmmm odd, i get the following error:
at ..(IList`1 )
|
|
|
Hey Hey, Both those things are working, thanks Ivan. Josh |
|