PDA

View Full Version : LINQ help required


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:
};

SouthwaterDave
05-03-2010, 09:47 PM
I'm not 100% sure of this but I believe that Linq to SQL is no longer being developed by Microsoft.

I recommend that you stick with the System.Data.SqlClient.

sammyboj
05-12-2010, 09:51 PM
you should use a nestled select that counts as you would do in T-SQL I guess?