views:

19

answers:

1

Hi

I have 3 tables. Blog and Tag have a many to many relationship. BlogTag is a junction table with a quantity column.

**Blog**
BlogID
Title

**Tag**
TagID
Name

**BlogTag**
BlogID
TagID
Quantity

I'm not sure how I handle the quantity column. I'd like it to store how many Blogs have a certain Tag Name

How do I deal with the quantity column when adding a new blog that has tags?

Thanks!

+1  A: 

Well, you'd need to calculate the quantity:

var q = (from b in Context.Blogs
         where b.BlogTags.Any(t => t.Tag.TagId == someId)
         select b).Count();

So you:

1. Add the blog
2. SaveChanges
3. For each tag on the new blog:
    1. Calculate the quantity, as above.
    2. Update the BlogTag.Quantity.
4. SaveChanges
Craig Stuntz