Linq to Entities:如何将 IQueryable 传递给方法
我对这个真的很困惑。我正在尝试将我的帖子传递给一种方法。我该如何去做:
var posts = from p in context.post
where (p.post_isdeleted == false && (object.Equals(p.post_parentid, null))
select new
{
p.post_date,
p.post_id,
FavoriteCount = (from f in context.favorites
where f.post.post_id == p.post_id
select new { f }).Count()
};
posts = QuestionList.FilterQuestion(posts, sort);
//the problem is here
//IQueryable is not the right type for posts. What type do I put in there
private static IQueryable FilterQuestion(IQueryable p, string sort)
{
I am really baffled on this one. I am trying to pass my posts vaiable to a method. How do I go about doing this:
var posts = from p in context.post
where (p.post_isdeleted == false && (object.Equals(p.post_parentid, null))
select new
{
p.post_date,
p.post_id,
FavoriteCount = (from f in context.favorites
where f.post.post_id == p.post_id
select new { f }).Count()
};
posts = QuestionList.FilterQuestion(posts, sort);
//the problem is here
//IQueryable is not the right type for posts. What type do I put in there
private static IQueryable FilterQuestion(IQueryable p, string sort)
{
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能对匿名对象执行此操作(
select new { }
)。您必须在其中指定强类型,例如:从这里,您可以使用@Luhmann 的答案和强类型 IQueryable。
You can't do this with anonymous objects (the
select new { }
). You'll have to specify a strong type in there, like:From here, you can use @Luhmann's answer and strongly-type IQueryable.