0

I'm using EF - Database first. There is 3 table with relationship like: Topic(1)-(n)TopicAndTag(n)-(1)Tag.

  • Topic: TopicId, TopicName
  • Tag: TagId, TagName
  • TopicAndTag: TagId, TopicId

Primary key and Foreign key has been added. Tag table contains available tags for user choose when add topic. But when new topic added, in database, I found there are new tags added in Tag table, These tag have the same name but new TagId. The relationship in TopicAndTag also has been added with new TagId unlike my available tags. How can i solve that problem.

  • 1) Make `TagName` field in _Tag_ table unique (in SQL). 2) This post [https://stackoverflow.com/a/9764392/6630084](https://stackoverflow.com/a/9764392/6630084) describe that the UNIQUE constraint automatically create an INDEX on the field - it is necessary for fast searching. 3) Check in code that a new `TagName` does not exist before adding it to the _Tag_ table. – Jackdaw Apr 17 '21 at 07:37
  • thank you, but it don't work – Lâm Nhựt Nguyễn Apr 17 '21 at 09:29

0 Answers0