Dynamic Where clause

by ssi 11. September 2013 10:55

Dynamic LINQ clause with  Join that allows items to  be concatenated.


 if (FormLoaded)             {                 var loans = dc.TRACKING_FILEs;                 var status = dc.TRACKING_FILE_As;                 var results = loans.Join(status, sta => sta.Loan_ID, tr => tr.Loan_ID,                   (tr, sta) => new { tr.Loan_ID, tr.f463_loan_status, tr.f450_loan_officer_code, tr.f2b1_last_name_buyer, tr.F430B1_dob_buyer, tr.f413_application_date, tr.f426_disbursement_date, tr.f7001_Buyer_1_First_and_Last_Name, tr.f13B1_B1_Curr_Street, tr.f14B1_B1_Curr_City, tr.f15B1_B1_Curr_St_Zip, tr.f440b1_Buyers_mailing_street_address, tr.f441b1_Buyers_mailing_city_State_zip, sta.f447b1_b1_email_address }).OrderBy(c => c.Loan_ID)                   .Select(r => new { r.Loan_ID, r.f450_loan_officer_code, r.f463_loan_status, r.f2b1_last_name_buyer, r.F430B1_dob_buyer, r.f413_application_date, r.f426_disbursement_date, r.f7001_Buyer_1_First_and_Last_Name, r.f13B1_B1_Curr_Street, r.f14B1_B1_Curr_City, r.f15B1_B1_Curr_St_Zip, r.f440b1_Buyers_mailing_street_address, r.f441b1_Buyers_mailing_city_State_zip, r.f447b1_b1_email_address });                 if (!string.IsNullOrEmpty(cbLO.Text))                 {                     results = results.Where(r => r.f450_loan_officer_code == cbLO.Text);                 }                 if (rbApplicationDate.Checked)                     results = results.Where(c => c.f413_application_date >= dtpStart.Value.Date                                                  & c.f413_application_date <= dtpEnd.Value.Date);                 if (rbDisbursementDate.Checked)                     results = results.Where(c => c.f426_disbursement_date >= dtpStart.Value.Date                                                  & c.f426_disbursement_date <= dtpEnd.Value.Date);                 if (ckStatus.Checked)                     results = results.Where(c => c.f463_loan_status == cbStatus.Text);                 dataGridView1.DataSource = results;                 lblStatus.Text = string.Format("Record Count: {0:#,##0}", results.Count());                 SetColumns();             }

Tags: ,

Add comment

biuquote
  • Comment
  • Preview
Loading

Calendar

<<  May 2026  >>
MoTuWeThFrSaSu
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

View posts in large calendar

RecentComments

None

Development Team @ Shelbysys

We develop custom database applications for our clients. Our development tool of choice is MS Visual Studio. 

Quotations

"Fill the unforgiving minute with sixty seconds worth of distance run."
Rudyard Kipling