如何使用LINQ与Group按条件一起加入多个表
我想获取具有内部列表详细信息的雇主列表以显示多个地址。我尝试了以下代码,并且能够获取EmpConnectionNumber,Empstate。我能够获取StoreID,StorestaffName,地址,商店和Storestafflist桌子的Contactnumber详细信息。
List<Model.ListEmployer.Employer> employer_list = null;
employer_List = (from a in Employer
join b in store on a.EmployerID equals b.EmployerID
join c in StoreAddress on b.StoreID equals c.StoreID
join d in StoreStaffList on c.storeAddressID equals d.StoreAddressID
where a.EmployerType == "Contract"
group new { a, c } by new { a.ConnectionNumber, c.state }
into grp
select new Model.ListEmployer.Employer
{
EmpConnectionNumber = grp.Key.ConnectionNumber,
EmpState = grp.Key.State,
AddressHistory = new List<Model.list Employer.AddressHistory>
{
new Model.ListEmployer.AddressHistory
{
StoreID = b.StoreID,
StoreStaffName = d.StoreStaffName,
Address = d.Address,
ContactNumber = d.ContactNumber
}
}
}). ToList();
任何人都可以帮助您完成此解决方案。
我的目的是在同一雇主列表中显示多个地址详细信息
I want to fetch the list of employer with inner list details to show multiple address. I have tried the following code and can able to fetch the EmpConnectionNumber, EmpState. I could able to fetch the StoreID, StoreStaffName, Address, ContactNumber details from store and StoreStaffList tables.
List<Model.ListEmployer.Employer> employer_list = null;
employer_List = (from a in Employer
join b in store on a.EmployerID equals b.EmployerID
join c in StoreAddress on b.StoreID equals c.StoreID
join d in StoreStaffList on c.storeAddressID equals d.StoreAddressID
where a.EmployerType == "Contract"
group new { a, c } by new { a.ConnectionNumber, c.state }
into grp
select new Model.ListEmployer.Employer
{
EmpConnectionNumber = grp.Key.ConnectionNumber,
EmpState = grp.Key.State,
AddressHistory = new List<Model.list Employer.AddressHistory>
{
new Model.ListEmployer.AddressHistory
{
StoreID = b.StoreID,
StoreStaffName = d.StoreStaffName,
Address = d.Address,
ContactNumber = d.ContactNumber
}
}
}). ToList();
Can anyone help on this solution to get it done.
my intension is to show multiple address details inside the same Employer list itself
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论