views:

47

answers:

3

I'm planning a new service for my ASP.NET MVC app and want to use tags. I've never really been too fond of tags, but SO delivers so I'll give it a shot.

Here's the simplified schema I'm thinking about:

Post Table
------------------
PK PostId BigInt (or perhaps uniqueidentifier)
...more post related fields...
Tags nvarchar(200)

Then I'd LINQ query something like:

_db.Posts.Where(p => p.Tags.Contains("TagToFind"));

Obviously, this is super simple, but would do what I need. Do you see any glaring problems with this? Likely performance, I'd imagine .Contains() isn't exactly fast.

UPDATE I plan to have a pre-built array of allowable tags that the user can pick from.

+1  A: 

This may work, but it will not scale unless you have a fulltext index on that column (and you query it using fulltext style queries).

Also normalizing tags (having a tags table) is kind of key, unless you do that you can not deal with merges or track when / who created what tag.

Sam Saffron
I updated my question. I'm going to have a pre-built array of allowable tags. As for the fulltext style query, what would that look like in LINQ? Anything special that would need to be done to the Tag field?
Chad
@Chad see: http://stackoverflow.com/questions/224475/is-it-possible-to-use-full-text-search-fts-with-linq
Sam Saffron
@Sam Saffron thanks for the link, very nice.
Chad
A: 

Do you see any glaring problems with this?

Well, let's give it a test:

INSERT INTO PostTable (PostId, Tags) 
VALUES (0, NULL), 
       (1, NULL), 
       (2, NULL), 
       (22, ''), 
       (55, 'Hello world!'), 
       (-99, 'Hello world!');

No relational key, no data integrity. No, absolutely no problems there ;)

onedaywhen
While I appreciate a bit of sarcasm here and there... I'm not sure I follow what you're saying... The tags are controlled on the business layer (an array of approved tags the user can select). If you mean I can't change the tag text later without heavy db query/updates... I can live with that.
Chad
A: 

Your query will not be able to use index. So, more posts => worse performance.

zendar
That I expected. Likely in the future I'd have to implement a full-text index and build a stored procedure to query it. Thanks!
Chad