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
|
Hello Shouldn't this: unitOfWork.Products.Where(p => p.ProductGroup.Name == "TestGroup"); be possible? I always get an exception. |
|
|
Hi Andre, Yes - that should be a perfectly acceptable query which should generate an EXISTS clause for ProductGroup.Name within the Products query. Could you post the details of the exception you are seeing? Also which provider are you targetting?
Jeremy |
|
|
Hi Jeremy The exception I am getting is a TargetInvocationException with an inner exception, holding the message "{"Unknown column 'CommodityGroups.Title' in 'where clause'"}" My entity classes: public class Product : Entity<int>
public class CommodityGroup : Entity<int>
UnitOfWork: public class MoritzUnitOfWork : UnitOfWork
and finally the part where everything should play together nicely: LightSpeedContext<MoritzUnitOfWork> context = new LightSpeedContext<MoritzUnitOfWork> As soon as the iteration starts, I get the exception. Maybe I made some mistakes? Thanks for your help. André |
|
|
Hello Andre, We haven't been able to reproduce this problem. Are you using 2.2 RTM or a nightly build? (If in doubt, check the DLL version of Mindscape.LightSpeed.dll and let us know that.) Could you log the generated SQL (unitOfWork.Context.Logger) and post it for us? Thanks! |
|
|
I have a similar problem with LightSpeed professional 3.0 Version: 3.0.789.12667 Attempted query: return from p in UnitOfWork.Personlocations where p.LocationId == locationid orderby p.Person select p.Person; Error received:
While the Person field is shown in the intellisense and is perfectly legal otherwise. This used to work with version 2.2 from july 2009
|
|
|
Is p.Person an assocation to a Person entity? If so, orderby p.Person isn't really a meaningful order clause, because what is the ordering on Persons? By ID? By some other property? It's better to spell out the desired ordering in the query e.g. orderby p.Person.Id. We'll take a look at this but my immediate reaction is that 2.2 should never have accepted that query in the first place. On the other hand, we appreciate that changes to the behaviour are inconvenient, especially if you have a lot of queries like this: is that the case? And it is definitely a bug that it's getting as far as the database and giving you an error there: we should at least be giving you a more meaningful error message e.g. "Cannot order on association properties." |
|
|
It is exactly as you guessed. Many thanks for the feedback on the query, I didn't spot the issue. I will install 3.0 again, correct the query and probably find that it works. And yes, we have lots of queries like these and will be having many, many more. |
|
|
I am having the exact same problem with the Lightspeed Professional 3.0 as well as the nightly build LightSpeed30Professional-20100302 I have in my model entities like Employee, Role, and the mapping entity EmployeeRole which has the foreign key from both the other two entities. Now i am trying to execute the following Query var _list = uow.Employees.Where(e=> e.EmployeeRoles.Any(er=> er.RolePk.RoleName == "Auditor" )).Select(e => e);
This raises the following exception Query Error: Could not find field [RoleName] on model [EmployeeRole]
Note: RolePk is the property in the EmployeeRole class that points to the parent Role object Any suggestions? ~ Sidharth |
|
|
In fact, when I said that the solution Ivan suggested was right, I didn't take the time to detail it further. While adressing a related Person entity directly in a where clause will obviously not work, adressing Person.Name doesn't work either. With the new (3.0) lighstpeed, if you start with say PersonAddresses in your unitofwork to get all the addresses for a Person, as in uow.PersonAddresses, then what you get back are always PersonAddresses, not Addresses for example. What I did was create extra iterations over the result to work around this. That is very easy, but it doesn't look like linq and I am not sure if it performs all that well. With the 2.2 version we did not have these problems. Example: (from pa in uow.PersonAddresses where pa.PersonId = 10 select pa.Addresses).SelectAll(); This will not give you Addresses, it will give you PersonAddresses and a bunch of exceptions if you think you are getting addresses.
|
|
|
Bart, could you provide us with a repro case for the issues you're seeing? I've been trying this out and I can't reproduce the problems you describe -- so perhaps I'm not understanding them correctly. For your Person.Name issue I ran the following query: var query = from c in UnitOfWork.Contributions and it seems to be working fine. For your PersonAddresses problem I tried this: var query = from ct in UnitOfWork.ContributionTags and for me it returns a collection of Tags, not a collection of ContributionTags. I'm not sure what I'm doing that's different to your scenario but if you can get me a repro program (console project or NUnit test and sample database) then I'd be happy to look into it for you. Thanks! |
|
|
Sidharth, we have reproduced the issue with using a traversal inside an Any inside a Where clause and we believe we have a fix. This fix will be included in the 22 April nightly build, available from about 1500 GMT. Please let us know if this solves your problem. Thanks for reporting this issue! Bart, it dawned on me that this is probably what you were referring to with the Person.Name issue -- if so this same fix will hopefully work for you too. Please let us know! |
|
|
Thanks Ivan. I will try the nightly build and let you know if I still face the issue. However, from my other post http://www.mindscape.co.nz/forums/Thread.aspx?ThreadID=3106 is there a possibility of exposing some utility methods for converting the LambdaExpression to QueryExpression. Is this something you can consider, since I already have build my logic to use the core base API for building dynamic query. And also the fact that I still cant use LINQ for nested subqueries in the where clause is a big issue that inhibits me from going the LINQ syntax way. ~ Sidharth
|
|