Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Linq对SQL:为什么';这不管用吗?_C#_Linq To Sql - Fatal编程技术网

C# Linq对SQL:为什么';这不管用吗?

C# Linq对SQL:为什么';这不管用吗?,c#,linq-to-sql,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; 你试过了吗 var posts = from p in db.cs_

为什么我会从以下方面得到编译错误

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;
你试过了吗

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

省去逗号,再加上一个“from”

你想做什么?在列表中选择所有具有线程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;

查看编译错误会很有帮助。如果是linq to sql,这将不起作用,正如问题中所标记的那样。您的答案排除了我的编译错误,但正如John Gietzen所提到的,如果是linq to sql,它将不起作用。很好的尝试,谢谢!