views:

49

answers:

1

I have a table of blog entries, a table of tags, and a table that intersects the tags to a blog entry.

I want to roll-up the tags of a blog entry into a comma delimited string to be returned in the same result set. This is how I've done it in SQL:

select 
    be.Title
    ,Tags = lower((
        select
            stuff((
                select distinct 
                    ',' + bc.Category
                from    
                    BlogEntryCategory bec
                    join BlogCategory bc on bc.BlogCategory_ID = bec.BlogCategory_ID
                where    
                    bec.BlogEntry_ID = be.BlogEntry_ID
                for xml path('')),1,1,'')        
        )
    )
from 
    BlogEntry be

I'm using for xml path to roll my tags up and I'm looking for the equivalent way to do this with LINQ.

+1  A: 

This is one of those situations where LINQ to SQL does not shine.

This code should be left in the database - it will be easier maintained and most likely will perform better there. Is there a particular reason you want to move this working code out of the database and into your application code? If it were up to me I would leave this code where it is.

Andrew Hare
I inherited a SQL2000 blog database and am trying to mimic some of the queries that I have on my own sql2005 server. The "for xml path" is not supported on SQL2000 so I thought I could use LINQ to SQL to fill that gap.
Coov