asp.net mvc 4 one to many relationship (article - tags)

守給你的承諾、 提交于 2019-12-04 21:37:38

First of all, you need to have a unique Id for both ArticleTag and Article. Then you need to insert ArticleID into Article Tag, because the entity needs to know which ArticleTags belong to an Article. Simplified, this is how it should look:

public class Article
{ 
public int ArticleID { get; set; }
public string Title { get; set; }
public DateTime Date { get; set; }
public string Anotation { get; set; }
}

public class ArticleTag
{
public int ArticleTagID { get; set; } 
public int ArticleID { get; set; } //This creates the link 1-M
public string TagName { get; set; }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!