在相同的select语句中从不同的db中选择相同的数据

时间:2011-05-16 19:17:45

标签: c# linq linq-to-sql

您好我想在同一个选择语句中从linq中选择多个数据库

// 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,
                           }).ToList();

// 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();

如果任何人有不同的方法来解决它,谢谢你发布它。

1 个答案:

答案 0 :(得分:1)

听起来你正在寻找Union(删除重复项)或Concat(保留重复项)方法。