christrinder
04-08-2010, 01:06 PM
Hi guys.
I'm relatively new to LINQ so some help here would be greatly appreciated. I'm used to T-SQL and could write this query in a few seconds flat using normal T-SQL, but I can't see how to do it in LINQ. Basically I want to return the forum threads with a count of the number of posts that belong to each and also the date of the last post. Threads and posts are in the same table, and a column (ParentId) links them to their respective PostId. I'm returning the results as an custom entity.
var items = from f in db.tblForums
join u in db.tblUserDetails on f.UserDetailsId equals u.UserDetailsId
orderby f.DateCreated descending
select new ForumThread()
{
PostId = f.PostId,
PostTitle = f.PostTitle,
FirstName = u.FirstName,
LastName = u.LastName,
PostCount = 1, :confused:
LastPost = DateTime.Now :confused:
};
I'm relatively new to LINQ so some help here would be greatly appreciated. I'm used to T-SQL and could write this query in a few seconds flat using normal T-SQL, but I can't see how to do it in LINQ. Basically I want to return the forum threads with a count of the number of posts that belong to each and also the date of the last post. Threads and posts are in the same table, and a column (ParentId) links them to their respective PostId. I'm returning the results as an custom entity.
var items = from f in db.tblForums
join u in db.tblUserDetails on f.UserDetailsId equals u.UserDetailsId
orderby f.DateCreated descending
select new ForumThread()
{
PostId = f.PostId,
PostTitle = f.PostTitle,
FirstName = u.FirstName,
LastName = u.LastName,
PostCount = 1, :confused:
LastPost = DateTime.Now :confused:
};