如何加入两个实体
我的实体名称客户
Public Class Customer
{
Name string {get;set;}
Address string {get;set;}
}
我得到了结果
Customer customer = this.customerService.GetAll();
Customer person = this.supplierService.GetAll();
如何在使用
单个实体预期的 linq 输出时加入两个实体
我的实体名称客户
Public Class Customer
{
Name string {get;set;}
Address string {get;set;}
}
Customer customer = this.customerService.GetAll();
Customer person = this.supplierService.GetAll();
如何在使用
单个实体预期的 linq 输出时加入两个实体
编辑
根据评论,您想将其加入一个名为 output 的实体中,因此您可以在匿名类型的帮助下完成并加入
var data = from c in customer
join p in person
on p.ID equals c.ID
select new
{
PersonName = p.Name,
CustomerName - c.Name
PersonAdd = p.Add
CustomerAdd = c.Add
};
加入将像这样工作
检查更多细节:SQL to LINQ (Visual Representation)
var data = from c in customer
join p in person
on p.ID equals c.ID
select c;
图像预设

或者
var cust = from c in Customers
join p in persons on
new { Name= c.Name, Address= c.Address }
equals
new { Name= p.Name, Address= p.Address }
select c;
首先
Customer customer = this.customerService.GetAll();
Customer person = this.supplierService.GetAll();
我的东西GetAll()必须返回集合或可枚举的客户。不是吗?然后,我觉得你需要联合而不是加入!