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
|
I am using hte lasest nightly. This release gives an error when doing a count on one of my unit tests. The test is [Test]
and the linq is public static IQueryable<User> GetActiveUsers(this IBaseRepository helper, int permissionId, int? userId = null) The table definitions are public static IQueryable<User> GetActiveUsers(this IBaseRepository helper, int permissionId, int? userId = null)
UserPermission object CREATE TABLE [dbo].[UserPermission](
User object CREATE TABLE [dbo].[Permissn](
The generated sql is SELECT
and is failing as userId in COUNT(UserId) is ambiguous. It should either be UserPermission.UserId or *
Sean |
|
|
Can you remember which build you were using before (when the test was passing)? No need to go digging around if you don't have the info to hand -- just might be helpful for us to track down the source of the regression. |
|
|
I suspect it was LightSpeed31Professional-20110316.
Sean |
|
|
Hi Sean, We're having trouble reproducing the SQL you're seeing -- we see an EXISTS subquery instead of an INNER JOIN -- and we suspect we're not seeing part of the problem. Is there something in the GetAll method that could be causing this, perhaps explicitly performing a join? Are you using the IQueryable<User> returned from GetActiveUsers in a projection (select) when you do the Count()? Could you post the query that causes the error? Thanks! |
|
|
The problem has something to with the property Active on the user object. It's defined using an Expression as per the blog post http://www.mindscapehq.com/blog/index.php/2010/09/14/ninja-domain-properties-in-lightspeed/ . public bool Active If I change my method from; public static IQueryable<User> GetActiveUsers(this IBaseRepository helper, int permissionId, int? userId = null) to public static IQueryable<User> GetActiveUsers(this IBaseRepository helper, int permissionId, int? userId = null) Then everything is sweetness and light.
All the way from the top to the bottom, my code is Unit test [Test]
Repository helper public static IQueryable<User> GetActiveUsers(this IBaseRepository helper, int permissionId, int? userId = null)
Repository public IQueryable<TEntity> GetAll<TEntity>() where TEntity : Entity
|
|
|
Aha, that was it! Thanks, Sean, reproduced and investigating. |
|
|
Thanks for alerting us to this. The problem was with the cocktail of ninja domain members, traversals, performing a Count on the traversal entity, the PK of the traversed-to table having the same name as the FK in the origin table and finally the traversal-plus-ninja-member being within a composite (&&/||) expression. There will be a candidate fix for this in the next nightly build. It covers the reported case but we have not yet tested it with more complex combinations, so do let us know if you still see problems. |
|
|
Works fine now in all my tests. Thanks |
|