在同一个 select 语句中从不同的数据库中选择相同的数据

发布于 2024-11-07 18:17:16 字数 1460 浏览 0 评论 0原文

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

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

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

If any one has a different approach to solving it, thanks for posting it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

死开点丶别碍眼 2024-11-14 18:17:16

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

It sounds like you're looking for the Union (removes duplicates) or Concat (keeps duplicates) methods.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文