Help in Groupby

Posts   
 
    
Posts: 97
Joined: 29-Apr-2009
# Posted on: 06-Jun-2009 07:21:32   

i have table "jobapplication"

in this table there is following fields

JobApplicationID JobDetailID CandidateID JobBoardID DateApplied

now i want to execute following query


select  count(candidateid)  from jobapplication group by jobdetailid;

so how can i achieve in LLBLgen?

please give me some sample code please.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 06-Jun-2009 08:24:11   

This is easy done with DynamicList. I assume from your previous threads, that your are using SelfServicing:

EntityFields fields = new EntityFields(1);
fields.DefineField(JobApplicationFields.CandidateId, 0);
fields[0].SetAggregateFunction(AggregateFunction.Count);

IGroupByCollection groupByClause = new GroupByCollection();
groupByClause.Add(JobApplicationFields.JobDetailId);

DataTable dynamicList = new DataTable();
TypedListDAO dao = new TypedListDAO();
dao.GetMultiAsDataTable(fields, dynamicList, 0, null, null, null, true, groupByClause, null, 0, 0);

Hope helpful wink

David Elizondo | LLBLGen Support Team
Posts: 97
Joined: 29-Apr-2009
# Posted on: 06-Jun-2009 08:59:19   

daelmo wrote:

This is easy done with DynamicList. I assume from your previous threads, that your are using SelfServicing:

EntityFields fields = new EntityFields(1);
fields.DefineField(JobApplicationFields.CandidateId, 0);
fields[0].SetAggregateFunction(AggregateFunction.Count);

IGroupByCollection groupByClause = new GroupByCollection();
groupByClause.Add(JobApplicationFields.JobDetailId);

DataTable dynamicList = new DataTable();
TypedListDAO dao = new TypedListDAO();
dao.GetMultiAsDataTable(fields, dynamicList, 0, null, null, null, true, groupByClause, null, 0, 0);

Hope helpful wink

Hi daelmo,

Thanks for reply, but problem is that due to some special requirement i cannot use TypedListDAO or DATATABLE or datareader. i can just use only entity and collection and i want to get output.

this is special requirement.

please help me

Posts: 97
Joined: 29-Apr-2009
# Posted on: 06-Jun-2009 09:19:21   

Hi daelmo

i have done like below and this also gives proper output. is this right method to do???

JobapplicationCollection JobApplicationDetail = new JobapplicationCollection(); Label1.Text = JobApplicationDetail.GetScalar(JobapplicationFieldIndex.CandidateId, null, AggregateFunction.Count, (JobapplicationFields.JobDetailId == 3)).ToString();

Posts: 97
Joined: 29-Apr-2009
# Posted on: 06-Jun-2009 09:19:57   

daelmo wrote:

This is easy done with DynamicList. I assume from your previous threads, that your are using SelfServicing:

EntityFields fields = new EntityFields(1);
fields.DefineField(JobApplicationFields.CandidateId, 0);
fields[0].SetAggregateFunction(AggregateFunction.Count);

IGroupByCollection groupByClause = new GroupByCollection();
groupByClause.Add(JobApplicationFields.JobDetailId);

DataTable dynamicList = new DataTable();
TypedListDAO dao = new TypedListDAO();
dao.GetMultiAsDataTable(fields, dynamicList, 0, null, null, null, true, groupByClause, null, 0, 0);

Hope helpful wink

Hi daelmo

i have done like below and this also gives proper output. is this right method to do???


JobapplicationCollection JobApplicationDetail = new JobapplicationCollection();
        Label1.Text = JobApplicationDetail.GetScalar(JobapplicationFieldIndex.CandidateId, null, AggregateFunction.Count,
            (JobapplicationFields.JobDetailId == 3)).ToString(); 

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 07-Jun-2009 22:46:26   

This is your first quey:

select count(candidateid) from jobapplication group by jobdetailid;

Such query generates more than one result (row), right?

If it generates more than one result you cannot use GetScalar. If you only want the total count, then the GetScalar is just fine simple_smile

David Elizondo | LLBLGen Support Team
Posts: 97
Joined: 29-Apr-2009
# Posted on: 08-Jun-2009 08:46:37   

daelmo wrote:

This is your first quey:

select count(candidateid) from jobapplication group by jobdetailid;

Such query generates more than one result (row), right?

If it generates more than one result you cannot use GetScalar. If you only want the total count, then the GetScalar is just fine simple_smile

Hi Daelmo,

Thanks for make me clear. well i want to know that in below code:


EntityFields fields = new EntityFields(1);
fields.DefineField(JobApplicationFields.CandidateId, 0);
fields[0].SetAggregateFunction(AggregateFunction.Count);

IGroupByCollection groupByClause = new GroupByCollection();
groupByClause.Add(JobApplicationFields.JobDetailId);

DataTable dynamicList = new DataTable();
TypedListDAO dao = new TypedListDAO();
dao.GetMultiAsDataTable(fields, dynamicList, 0, null, null, null, true, groupByClause, null, 0, 0);

how to display the output above code in gridview??? because dao.GetMultiAsDataTable return bool value.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 08-Jun-2009 09:20:44   

DataTable dynamicList = new DataTable(); TypedListDAO dao = new TypedListDAO(); dao.GetMultiAsDataTable(fields, dynamicList, 0, null, null, null, true, groupByClause, null, 0, 0);

GetMultiAsDataTable() fills the passed in DataTable (dynamicList...in your case), so you can bind this dataTable to the gridView.

Posts: 97
Joined: 29-Apr-2009
# Posted on: 08-Jun-2009 10:01:37   

Walaa wrote:

DataTable dynamicList = new DataTable(); TypedListDAO dao = new TypedListDAO(); dao.GetMultiAsDataTable(fields, dynamicList, 0, null, null, null, true, groupByClause, null, 0, 0);

GetMultiAsDataTable() fills the passed in DataTable (dynamicList...in your case), so you can bind this dataTable to the gridView.

thanks walaa,

its too easy after ur solution. thanks.

hip hip hurray.