Reputation: 47
my entity name customer
Public Class Customer
{
Name string {get;set;}
Address string {get;set;}
}
Customer customer = this.customerService.GetAll();
Customer person = this.supplierService.GetAll();
how to join two entities in using linq
output exepected for single entity
Upvotes: 2
Views: 356
Reputation: 176956
EDIT
As per the comment you want to join this in one entity called output , so you can do it with the help of anonymous type and join
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
};
join will work like this
Check for more detail : SQL to LINQ ( Visual Representation )
var data = from c in customer
join p in person
on p.ID equals c.ID
select c;
image presetnation
or
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;
Upvotes: 1
Reputation: 33391
For first
Customer customer = this.customerService.GetAll();
Customer person = this.supplierService.GetAll();
I thing GetAll()
must return collection or enumerable of customers. Isn't it?
Then, i thing you need union instead join!
Upvotes: 1