Papy214 wrote:
But if my query return more than one column with one for the count result ?
Example:
SELECT Patients.gender, Count(Patients.gender) AS CountOfgender
FROM Patients
GROUP BY Patients.gender;
How to get CountOfgender ? ... it's not a Patients property ...
I see. There are two ways. Create your own type like following:
Code:
class MyType
{
public MyType() {}
public MyType(string gender, int count) { /* Put code here... */ }
}
Then in your query you do this:
Code:
select new MyType(Patients.gender, Count(Patiens.gender)) from Patiens...
I am not sure about the query - wanted to show just an idea I've seen already...
Another approach is a derivative from my former message but if you have two collumns then you just need to use an UniqueResult<object[]> and as a result you get an array of objects, where each collumn is stored in separate array element so youo do this:
Code:
object[] result = q.UniqueResult<object[]>();
string gender = result[0];
int count = (int)result[1];
Indexing follows your column order in the query. I still did not check the int type... Note that it seems that the second approach is easier (thought less clear in comlex architectures...) and here I would choose it.