查询模型内部,如何获取特定类中的项目数
我想出了这个:
[NotMapped]
public int ThreadsInBoard
{
get
{
ForumContextContainer ctx = new ForumContextContainer();
int thr = (from p in ctx.BoardSet
from x in ctx.ThreadSet
where p.BoardID == x.Board.BoardID
select p).Count();
}
}
我想做的是特定板上的线程数。 该查询实际上返回数据库中每个可能线程的计数并对其进行分配。 以下是涉及的类
public partial class Board
{
public int BoardID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public bool IsVisibleToGuests { get; set; }
public bool IsLocked { get; set; }
public Forum Forum { get; set; }
public ICollection<Thread> Thread { get; set; }
}
public partial class Thread
{
public int ThreadID { get; set; }
public User User { get; set; }
public ICollection<Post> Post { get; set; }
public Board Board { get; set; }
public ICollection<Subscription> Subscription { get; set; }
public ICollection<Poll> Poll { get; set; }
}
I've come up with this:
[NotMapped]
public int ThreadsInBoard
{
get
{
ForumContextContainer ctx = new ForumContextContainer();
int thr = (from p in ctx.BoardSet
from x in ctx.ThreadSet
where p.BoardID == x.Board.BoardID
select p).Count();
}
}
What I want to do is the count of threads, that are in the specific board.
This query actually return count of every possible thread in database and assign it.
Below are involved classes
public partial class Board
{
public int BoardID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public bool IsVisibleToGuests { get; set; }
public bool IsLocked { get; set; }
public Forum Forum { get; set; }
public ICollection<Thread> Thread { get; set; }
}
public partial class Thread
{
public int ThreadID { get; set; }
public User User { get; set; }
public ICollection<Post> Post { get; set; }
public Board Board { get; set; }
public ICollection<Subscription> Subscription { get; set; }
public ICollection<Poll> Poll { get; set; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设此类具有 boardId 属性
assuming this class has the boardId property