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
|
Me again! must be my week for asking questions.
if I want to do a count over the destinct items in a column how would I acheive that, I can get a select distinct and count after the select but would ideally like to generate a count distinct column from SQL.
Any ideas? O |
|
|
Managed to work this out using the unitofwork.calculate method and distinct=true on the query.
Thanks O |
|
|
Use the Distinct() and Count() operators: var count = (from m in UnitOfWork.Contributions Generated SQL: SELECT |
|
|
I'm presuming this doesn't support selecting distinct across more than one field?
currently it tries to do a distinct * so not sure what to do there.
O |
|
|
You presume right: to the best of our knowledge this isn't even supported at the SQL level. (E.g. SELECT COUNT(DISTINCT field1, field2) FROM ... is a syntax error on SQL Server.) The closest you can get is to do this client-side: var count = (from m in UnitOfWork.Contributions Obviously this will be less efficient than if you could get the database to calculate the count for you, but as I said, we believe that what you're asking for just isn't supported in the database. |
|
|
I was more thinking of a way of doing: SELECT COUNT(*) FROM where..... ) as des
|
|
|
Facepalm, as JD would no doubt say. Yes, that would work. We'll look into that, though I don't think we'll be able to do it in time for LightSpeed 3. Thanks. |
|