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! I'm currently porting an application to your great product from Linq2Sql and i'm down to my last bugs :D. One of these bugs is an issue with the LINQ Count() method. I have an ExtranetUser table, a RightGroup table and a relation table named MemberOf (very basic, yeah). MemberOf is an auto-through association (if that helps). The following piece of code was working with Linq2Sql. Here is the problematic piece of code: var users = this._extranet.MemberOfs.Where(g => g.RightGroup.Role == role).Select(g => g.ExtranetUser); if (searchInformation.HasExpression) users = users.Where(u => I get the exception: System.Data.SqlClient.SqlException : Invalid column name 'ExtranetUser'. Here is the SQL i got from the trace logger (it didn't go into the IF, but we must still take it into consideration): SELECT Is there something i am missing? Is there a way to re-write the query? Thanks for your help!
Best regards, -Jonathan |
|
|
Hi Jonathan, ExtranetUser is the actual entity property, is that correct? If so, this will be the cause of the problem, you will want to select ExtranetUserId rather than ExtranetUser. e.g. Select(g => g.ExtranetUserId) in your query above. It would be ideal to be able to have LightSpeed automatically translate this for you rather than you having to update your query, so Ive logged a ticket in our backlog to include this in a later version. I will let you know once we have added this in.
Jeremy |
|
|
Hi Jeremy, ExtranetUser is the actual entity, yes. Selecting g.ExtranetUserId will not let me filter by the search expression (content of the IF loop), which is normal since the query would return an IQueryable<int>. In the [users.Where(u => u.UserName.Contains(searchInformation.SearchExpression)] statement, UserName would not be a member of int.
The big picture here is i want to get a paged, sorted and filtered list of users of a specified role. I'm first selecting all users of the given role (IQueryable<ExtranetUser>), i'm adding some where clauses (Content of the IF loop) for the filtering, i'm then catching the count of the filtered list for paging purposes. The rest of the code, which i left out, applies sorting, the usual .skip().take() for paging and returns a ToList() to get a List<ExtranetUser>.
I don't think i was thorough enough in my explication of what my intents were. The exception was raised from the Count(), so i decided to leave out the rest of my method.
So, do I need to get the filtered list of users and the count of that filtered list with two seperate linq queries? If so, how would i go about filtering (content of the IF loop) if i can't select g.ExtranetUser? I can send you a test project that reproduces the problem tomorrow when i get to work if you want.
Best regards, -Jonathan |
|
|
Hi Jonathan, Yes if you are able to send through a test project that would be most useful :)
Jeremy |
|
|
Hi Jeremy, Sorry for the late answer, it's monday morning here :) Attached to this post is a small project reproducing the problem i'm experimenting. Needless to say you'll have to re-reference Lightspeed and NUnit with your working copies as well as changing the connection strings. The project contains a test class containing 4 tests, 2 of which fails related to my problem, the other 2 passes using a workaround (a rewrite as explained in previous posts). I'm currently using the workaround so there's no rush. The failing tests work with Linq2Sql, so you still might want to look into it. There's no better way for two developpers to understand eachother than failing tests ;) Happy bug hunting!
-Jonathan |
|
|
Hi Jonathan, Thanks for the consise sample. I can repro the original issue as described so we will get hunting Tests are good like that :)
Jeremy |
|
|
Hi Jonathan, I have put through 2 fixes which cover the 2 failing tests in your repro project. These will be included in the next nightly build (20100326) if you are able to grab that and verify things at your end as well. Let us know if this covers off the issues for you. Thanks again for the concise repro project.
Cheers, Jeremy |
|
|
Works like a charm!
Thanks! -Jonathan |
|