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, Lightspeed is generating an invalid SQL query when attempting to use the UOW.Remove(QueryExpression) method where the QueryExpression contains an aggregate sub expression. The queryexpression generates the expected SQL when using UOW.Find(QueryExpression) but when using it with Remove() the SQL incorrectly references the (abitrary) name of the subexpression as a field on the table. I've attached a repro that shows the problem, Cheers, Greg |
|
|
Hi Greg, Thanks for the detailed repro - we are having a look into this today and I will let you know once we have a fix ready :)
Jeremy |
|
|
Hi Greg, I have added a candidate fix for this which enables support for sub expressions within delete queries (which only actually possible to elaborate via delete by query however) and this will be available in the next nightly build (20100925). One thing to be careful of however is if you are doing a delete which would cause a cascade where the criteria is against a dependant. e.g. Assume you have Contributions -> Comments and you want to delete all Contributions which have 2 Comments (this is similar to the example you provided in the repro). The delete will cascade to the Comments table because it is dependant, and will remove the comments where they are associated with contributions which have 2 comments. The delete will then try and delete Contributions with 2 Comments, but because the comments are no longer present there will be no rows affected :) This is just a restriction of how you are trying to specify the deletion of course, because if you tried to delete just the Contributions you would fall foul of FK constraints, so in these cases you would want to manually delete the entities by loading them in via a query with subexpression and then removing each candidate via UnitOfWork.Remove(entity) which would allow the deletions to be specified by Id.
Jeremy
|
|
|
To add to Jeremy's comment in the final paragraph, if the cost of loading the entities is a concern, then you should be able to use a projection to load just the IDs, then use UnitOfWork.Remove(Query) with Entity.Attribute("Id")-based queries to perform the delete. Haven't tried this though! |
|