how to select all the columns from both query ( Join case) , see the example below :
Code
var particiapants = from p in data.getAllParticipant() from l in dt.GetAll() where p.IdParticipant == l.IdParticipant select p , l ; ???I want to display all the columns , and i dont want to do :
Code
p.name , p.job .........
Shuvo Sarker138 reputationPosted Sep 18, 2016, 11:46 PM EDT
var customers = new List { new Customer { CompanyId = “AC”, CustomerId = “Customer1” }, new Customer { CompanyId = “not-AC”, CustomerId = “Customer2” }, }; var userCustomers = new List { new UserCustomer { CompanyId = “AC”, CustomerId = “Customer1”, User = “not-admin” }, new UserCustomer { CompanyId = “AC”, CustomerId = “Customer1”, User = “admin” }, new UserCustomer { CompanyId = “AC”, CustomerId = “Customer2”, User = “not-admin” }, new UserCustomer { CompanyId = “AC”, CustomerId = “Customer2”, User = “admin” }, new UserCustomer { CompanyId = “not-AC”, CustomerId = “Customer1”, User = “not-admin” }, new UserCustomer { CompanyId = “not-AC”, CustomerId = “Customer1”, User = “admin” }, new UserCustomer { CompanyId = “not-AC”, CustomerId = “Customer2”, User = “not-admin” }, new UserCustomer { CompanyId = “not-AC”, CustomerId = “Customer2”, User = “admin” } }; Linq Expression: var query = from c in customers join uc in userCustomers on new { c.CompanyId, c.CustomerId } equals new { uc.CompanyId, uc.CustomerId } where c.CompanyId == “AC” && uc.User == “admin“ select c;Ali Haider197 reputationPosted Sep 4, 2016, 5:09 AM EDT
oining on multiple columns in Linq to SQL is a little different.
You have to take advantage of anonymous types and compose a type for the multiple columns you wish to compare against.
This seems confusing at first but once you get acquainted with the way the SQL is composed from the expressions it will make a lot more sense, under the covers this will generate the type of join you are looking for.
EDIT Adding example for second join based on comment.
Tapan PatelRank #614 · 3.9K reputationPosted Sep 7, 2016, 1:21 PM EDT
Bikesh SrivastavaRank #108 · 20.3K reputationPosted Sep 7, 2016, 10:53 PM EDT
Pooja Dixit36 reputationPosted Jun 6, 2017, 4:48 AM EDT
Ankur Goel4 reputationPosted Sep 20, 2016, 12:43 AM EDT
pankaj rai3 reputationPosted Oct 16, 2016, 10:25 PM EDT