实体框架ctp5使用数据注释的一对多关系
我有两个班级大学和系,假设存在一对多关系,即一所大学有许多系
public class University
{
public string UniversityId;
public string UniversityName;
public List<Department> Departments;
}
public class Department
{
public string DepartmentId;
public string DepartmentName;
}
我想使用实体框架数据注释功能ctp5来映射这种关系 有人可以给我指出任何关于数据注释功能的好教程吗
I have two classes university and department, suppose there is one to many relationship i.e one university has many departments
public class University
{
public string UniversityId;
public string UniversityName;
public List<Department> Departments;
}
public class Department
{
public string DepartmentId;
public string DepartmentName;
}
I want to map this relationship using Entity framework data annotation feature ctp5
and also can someone point me to any good tutorial of data annotation features
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅此 http://blogs .msdn.com/b/efdesign/archive/2010/06/01/conventions-for-code-first.aspx
欣快是正确的,你不需要注释。然而,如果你想在对象之间建立多种关系,你可能需要使用 Fluent API。
所以你需要的唯一代码是
See this http://blogs.msdn.com/b/efdesign/archive/2010/06/01/conventions-for-code-first.aspx
Euphoric is correct you do not need annotations. However if you want to have multiple relationships between objects you may need to use the fluent API.
So the only code you would need is
IMO 不需要注释。如果您的上下文中同时存在这两个类,那么框架本身会识别这种关系并根据需要创建表。
并确保创建从部门到大学的参考。
IMO there is no need for anotation. If you have both classes in your context, then framework itself recognizes this relation and creates tables as required.
And to be sure create reference from Department to University.