tags:

views:

37

answers:

2

Can someone convert this query to linq2sql for me? Trying to teach myself linq to see if I want to use it for a small project, and getting hung up on the smallest details...

SELECT  
  Warrant.ID, 
  Warrant.MeetingDate, 
  Warrant.MeetingType, 
  Warrant.Notes, 
COUNT(WarrantArticles.ID) AS Cnt
FROM  Warrant INNER JOIN  WarrantArticles ON Warrant.ID = WarrantArticles.WarrantID
   group by   Warrant.ID, Warrant.MeetingDate, Warrant.MeetingType, Warrant.Notes
+1  A: 

There is a great tool that will do this for you. The tool is called Linqer (I have no affiliation with it). It will take most SQL statements and convert them to a Linq query. I have used it many times to help me convert more difficult queries.

Randy Minder
+1  A: 

Daniel asked about your ObjectContext because it would be hard to give you a definitive answer without knowing that.

That being said, your query might look something like this

var result = from w in context.Warrant select new {w.ID, w.MeetingDate, w.MeetingType, w.Notes, w.Articles.Count};

or

var result = context.Warrant.Select(w=> new new {w.ID, w.MeetingDate, w.MeetingType, w.Notes, w.Articles.Count});
Sky Sanders
Not exactly the answer, but gave me the missing clue for what I needed - thanks.
EJB