select same data from different db in same select statement
hi i want to select multiple db from linq in same select statement
// gets specific information from Cabinet table
var chassi = (from a in db.Cabinets
from b in db.Commodities
from e in db.sArticleNumbers
where
kjopKollonne.Contains(e.ArtNum) &&
a.ArticleNumberID == e.ID &&
a.ArticleNumberID == b.ArticleNumberID
select new {
ArtNum = e.ArtNum,
Price = b.Price,
ModelName = a.ModelName,
}).ToLi开发者_运维百科st();
// gets specific information from cpu table
var cpu = (from a in db.cpu
from b in db.Commodities
from e in db.sArticleNumbers
where
kjopKollonne.Contains(e.ArtNum) &&
a.ArticleNumberID == e.ID &&
a.ArticleNumberID == b.ArticleNumberID
select new {
ArtNum = e.ArtNum,
Price = b.Price,
ModelName = a.ModelName,
}).ToList();
// Joins CPU and chassi information to one output
var query1 = (from a in chassi
from b in cpu
select new {
ArtNum = a.ArtNum and b.ArtNum, <-- problem
Price = a.Price,
ModelName = a.ModelName,
}).ToList();
If any one has a different approach to solving it, thanks for posting it.
It sounds like you're looking for the Union
(removes duplicates) or Concat
(keeps duplicates) methods.
精彩评论