2
Answers

How to fill Model with related data w.r.t. model Id

umair mohsin

umair mohsin

1y
400
1
private void GetData(Candidate c)//for candidate index page
{
    c.Alerts = db.Alerts.Where(a => a.CanId == c.CanId).ToList();
    c.Bookmarks = db.SavedJobs.Where(sv => sv.CanId == c.CanId).ToList();
    c.Applications = db.Applications.Where(app => app.CanId == c.CanId).ToList();
}

alerts, bookmarks,applications all are list from different tables i am fetching records from them using CanId

is there any way to do this task using generic repository( i just pass candidate in generic repo and all three list wrt id would return to me) or what is the long query to fill above lists with appropriate data.

what is the most suitable way to fill canditae model and pass it to view in  terms of  best practices

Answers (2)