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
|
Its me again :) The problem relates a bit to: http://www.mindscape.co.nz/forums/Thread.aspx?ThreadID=2411 I switched on the sql console logger when loading and creating self referenced menuitems. Here i mentioned that there are a lot of SQL statement are generated - what a surprise ;) Now all i load everything into the memory and do all here - what a speed. And now my question or situation when i use this where clause: allMenuItems = unitOfWork.Find<MenuItem>().Where(mi => mi.IsActive).ToList() Its working, but when looking a bit closer to the generated SQL-Statement i saw, that there no where clause is the statement. So i assume that first all is loaded and the where is done later in the memory - i didn't expect that, because i thought LINQ is working with lightspeed. When using that query the where clause is generated: allMenuItems = unitOfWork.Find<MenuItem>(Entity.Attribute("IsActive") == true).ToList() So the second query is my current solution, but is .where not generating the WHERE clause, because i thought there is a LINQ support. And using where is more usable than using Entity.Attribute ... from my point of view. Since i used everwhere the linq where extension in my project, i have to change now them. Or is there another solution? Best regards Markus |
|
|
After posting, i took a short look in your blog about LS 3.0 Beta1: "Huge querying enhancements": is that what i mean? If so, when goes the 3.0 productive? By the way I am very exited about 3.0 - the migration tool seems to exact that what i used before in rubyonrails. wow |
|
|
Hello Markus, This occurs because you are mixing the Find() method with a LINQ filter. Find requires you to pass a LightSpeed Query or QueryExpression object; if you don't, it just fetches everything. Find doesn't know about LINQ. So Find().Where(...) tells LightSpeed to fetch everything, then performs the filtering on the resultant list using LINQ to Objects. Put another way, this is the difference between how LINQ handles IEnumerable and IQueryable. Find returns an IEnumerable, not an IQueryable, which means LINQ operators like Where run client-side (i.e. using LINQ to Objects). To have your LINQ operators translated into SQL, you need to apply them to an IQueryable. In LightSpeed, you do that using the Query extension method: unitOfWork.Query<MenuItem>().Where(...); or, more usually, with a strong-typed unit of work that encapsulates the Query call: public class MyModelUnitOfWork : UnitOfWork { unitOfWork.MenuItems.Where(...); If you are using the designer, it will create a strong-typed unit of work for you if your project targets .NET 3.5 or above. Note that Query is an extension method so you will need a using Mindscape.LightSpeed.Linq at the top of the file if you choose to spell it out explicitly. Regarding LightSpeed 3, the querying enhancements refer to things like joins, groups, subexpressions and subqueries. We won't be changing Find() to return an IQueryable -- that's what the Query() method is for. We don't have a final date for releasing LS3 yet because there is still a bit of polishing and cleanup to do, and we still have to work on documentation and samples, but I would expect it to be in the next few weeks. |
|
|
Hello Ivan, thank you very much. I learned a lot again. So LS does want i want - fine. And by the way i revealed why i can't use strong-typed unitofwork entities: before (i always casted to UnitOfWork): private UnitOfWork unitOfWork ...l; now: private MyUnitOfWork unitOfWork ...; Then it was no wonder why i can't use: unitofwork.MenuItems - now it works Thanks again and have i nice day Markus |
|