在同一选择语句中选择来自不同数据库的相同数据



嗨,我想在同一选择语句中从 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();

如果有人有不同的解决方法,感谢您发布它。

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

相关内容

  • 没有找到相关文章

最新更新