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

时间:2009-10-15 23:27:22

标签: c# linq-to-sql

为什么我会收到以下编译错误?

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;

2 个答案:

答案 0 :(得分:6)

你想做什么?选择列表中包含线程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;

答案 1 :(得分:2)

你试过吗

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

省略逗号并添加另一个'from'