开发者

Linq To SQL: Why doesn't this work?

Why do I get compilation errors from the following?

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.Thread开发者_开发问答ID == t
    select p.ThreadID;


What are you trying to do? Select all posts that have thread IDs in the list?

Then something like this would 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
    where threadIds.Contains(p.ThreadID)
    select p.ThreadID;


Did you Try

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

Leave out the comma and add another 'from'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜