两个班级之间的关系 [英] Relationship between 2 classes
本文介绍了两个班级之间的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们如何维护实体框架中两个类之间的关系?
解决方案
public class 博客
{
public < span class =code-keyword> int BlogId { get ; set ; }
public string 名称{ get 跨度>; set ; }
public virtual 列表< post>帖子{获取; set ; }
}
public class 发布
{
public int PostId { get ; set ; }
public string 标题{ get 跨度>; set ; }
public string 内容{ get 跨度>; set ; }
public int BlogId {获得跨度>; set ; }
public 虚拟博客博客{ get < /跨度>; set ; }
} < / 发布 > 跨度>
How can we maintain the relationship between the two classes in the entity frame work?
解决方案
public class Blog { public int BlogId { get; set; } public string Name { get; set; } public virtual List<post> Posts { get; set; } } public class Post { public int PostId { get; set; } public string Title { get; set; } public string Content { get; set; } public int BlogId { get; set; } public virtual Blog Blog { get; set; } }</post>
这篇关于两个班级之间的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文