c# - Linq for a hierarchical relationship model with Entity Framework, Filtering nested tables -
i have got following database model, need query company entity specific username table aspnetusers. not how filter , drill related hierarchical tables using linq lambda expression entity framework. domain classes have foreign keys , navigation properties required.i appreciate help.
from understand given solution . hope may you.
//test data datatable companies = new datatable(); companies.columns.add("companyid", typeof(string)); companies.columns.add("companyname", typeof(string)); datatable teams = new datatable(); teams.columns.add("companyid", typeof(string)); teams.columns.add("teamid", typeof(string)); datatable applicationuserteam = new datatable(); applicationuserteam.columns.add("teamid", typeof(string)); applicationuserteam.columns.add("applicationuserid", typeof(string)); datatable aspnetusers = new datatable(); aspnetusers.columns.add("id", typeof(string)); aspnetusers.columns.add("name", typeof(string)); companies.rows.add("10", "infosys"); companies.rows.add("12", "tech mahindra"); teams.rows.add("10", "t18"); teams.rows.add("12", "t12"); applicationuserteam.rows.add("t10", "120"); applicationuserteam.rows.add("t12", "110"); aspnetusers.rows.add("110", "king"); aspnetusers.rows.add("112", "little"); var id = aspnetusers.asenumerable().where(s => s.field<string>("name").equals("king")).select(s => s.field<string>("id")).first(); var teamid = applicationuserteam.asenumerable().where(s => s.field<string>("applicationuserid").equals(id)).select(s => s.field<string>("teamid")).first(); var companyid = teams.asenumerable().where(s => s.field<string>("teamid").equals(teamid)).select(s => s.field<string>("companyid")).first(); var company = companies.asenumerable().where(s => s.field<string>("companyid").equals(companyid)); foreach (var item in company) { console.writeline(item[0] + " " + item[1]); }
Comments
Post a Comment