繁体   English   中英

Linq To SQL:为什么不起作用?

[英]Linq To SQL: Why doesn't this work?

为什么会从以下内容得到编译错误?

int[] threadIDs = { 4,5,6,7,8,9,10,11,12,13,14,15,16,17 };
CSDataContext db = new CSDataContext();
var posts = from p in db.cs_Posts, t in threadIDs
    where p.ThreadID == t
    select p.ThreadID;

你想做什么? 选择列表中所有具有线程ID的帖子?

然后像这样的东西会工作

int[] threadIDs = {4,5,6,7,8,9,10,11,12,13,14,15,16,17};
CSDataContext db = new CSDataContext();
var posts = from p in db.cs_Posts
    where threadIds.Contains(p.ThreadID)
    select p.ThreadID;

你试过了吗

var posts = from p in db.cs_Posts
            from t in threadIDs
            where p.ThreadID == t
            select p.ThreadID;

省略逗号并添加另一个“来自”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM