在同一个 select 语句中从不同的数据库中选择相同的数据
嗨,我想在同一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您正在寻找
Union
(删除重复项)或Concat
(保留重复项)方法。It sounds like you're looking for the
Union
(removes duplicates) orConcat
(keeps duplicates) methods.