S
shapper
Hello,
I created 3 few tables that have Many to Many relationships:
Posts (PostId PK)
Files (FileId PK)
PostsTags (PostId PK, TagId PK)
FilesTags (FileId PK, TagId PK)
Tags (TagId PK, TagName)
First of all, by dragging the tables to a dbml file the classes are
not ready for such Many to Many relationship:
Posts > PostsTags > Tags
and
Files > FilesTags > Tags
Does anyone knows how to do this?
And the behavior which seems logic to me (but maybe I am wrong) should
be:
(The example for Posts. For files is the same)
- When a tag is added to a Post, a record is added to TagsInPosts.
If the Tag (given its TagName) does not exist in Tags then it is
created in Tags table.
- When a tag is removed from a post then it is deleted from PostsTags.
If that tag is no longer associated with a Post or a File through
PostsTags and FilesTags then it is deleted from Tag.
Can I implement this logic in my LINQ classes or should I need to
create triggers, besides the constrains I enumerated, in my database?
I only find simple one-to-one examples and the only many-to-many
example is back to May 2006.
Thanks,
Miguel
I created 3 few tables that have Many to Many relationships:
Posts (PostId PK)
Files (FileId PK)
PostsTags (PostId PK, TagId PK)
FilesTags (FileId PK, TagId PK)
Tags (TagId PK, TagName)
First of all, by dragging the tables to a dbml file the classes are
not ready for such Many to Many relationship:
Posts > PostsTags > Tags
and
Files > FilesTags > Tags
Does anyone knows how to do this?
And the behavior which seems logic to me (but maybe I am wrong) should
be:
(The example for Posts. For files is the same)
- When a tag is added to a Post, a record is added to TagsInPosts.
If the Tag (given its TagName) does not exist in Tags then it is
created in Tags table.
- When a tag is removed from a post then it is deleted from PostsTags.
If that tag is no longer associated with a Post or a File through
PostsTags and FilesTags then it is deleted from Tag.
Can I implement this logic in my LINQ classes or should I need to
create triggers, besides the constrains I enumerated, in my database?
I only find simple one-to-one examples and the only many-to-many
example is back to May 2006.
Thanks,
Miguel