Amenda Aisha

Amenda Aisha

  • NA
  • 13
  • 5.9k

Entity framework -Linq

Jul 13 2016 5:13 AM
I have two table called Change Request and Task list
change request has one or many task ,
task list task is belongs to an exactly one change request
so in a different form there is a combo box which contain change request ids from change request table ----> here my requirement is to display task list data in a datagrid when selecting a change request id
furthermore it should search for that selected id with the task list table and retrieve only matching records.
 
here is my code
----------------------------------------------
// load task detalis
private void LoadtaskList()
{
//cr id from change request table -----> match with task table and get data belongs to that cr id
var crId = Int32.Parse(cbsearch.SelectedValue.ToString());
BindingSource task = new BindingSource();
task.DataSource = db.cr_tasks.Where(e => e.change_request_id == crId && e.is_active == true)
.Select(x => new
{
x.task_id,
x.task_name,
x.responsible_person,
x.service.name,
x.task_start_date,
x.task_completion_date,
x.is_completed_status,
x.service_id
}).ToList();
if (task.DataSource != null)
{
dgvtask_details.DataSource = task;
}
}
 

Answers (5)