.net 实体框架ctp5使用数据注释的一对多关系
我有大学和系两个班,假设有一对多的关系,即一所大学有许多系.net 实体框架ctp5使用数据注释的一对多关系,.net,data-annotations,entity-framework-ctp5,.net,Data Annotations,Entity Framework Ctp5,我有大学和系两个班,假设有一对多的关系,即一所大学有许多系 public class University { public string UniversityId; public string UniversityName; public List<Department> Departments; } public class Department { public string DepartmentId; public string
public class University
{
public string UniversityId;
public string UniversityName;
public List<Department> Departments;
}
public class Department
{
public string DepartmentId;
public string DepartmentName;
}
公立大学
{
公立弦乐大学;
公共字符串大学名称;
公布部门名单;
}
公共课系
{
公共字符串DepartmentId;
公共字符串DepartmentName;
}
我想使用实体框架数据注释功能ctp5映射这种关系
还有谁能给我指一下任何关于数据注释功能的好教程吗?我不需要解释。若您的上下文中同时有这两个类,那个么框架本身会识别这个关系,并根据需要创建表 请务必创建从系到大学的参考资料。请参见此 欣快是正确的,你不需要注释。但是,如果要在对象之间建立多个关系,可能需要使用fluent API 因此,您需要的唯一代码是
public class University
{
public string UniversityId { get; set; }
public string UniversityName { get; set; }
public List<Department> Departments { get; set; }
}
public class Department
{
public string DepartmentId { get; set; }
public string DepartmentName { get; set; }
public University University{ get; set; }
}
公立大学
{
公共字符串UniversityId{get;set;}
公共字符串UniversityName{get;set;}
公共列表部门{get;set;}
}
公共课系
{
公共字符串DepartmentId{get;set;}
公共字符串DepartmentName{get;set;}
公立大学{get;set;}
}
您所说的“确保创建从系到大学的参考”是什么意思