Entity Framework中 把实体框架的构造函数设置为私有的之后 查询时获取不到它导航属性的值 35
publicclassEmployee{publicGuidId{get;set;}publicstringName{get;set;}HashSet<Info>_inf...
public class Employee
{
public Guid Id { get; set; }
public string Name { get; set; }
HashSet<Info> _info;
public virtual ICollection<Info> Infos
{
get
{
if (_info == null)
_info = new HashSet<Info>();
return _info;
}
private set
{
_info = new HashSet<Info>(value);
}
}
}
public class Info
{
public Guid Id { get; set; }
public string Department { get; set; }
public string Duty { get; set; }
HashSet<Employee> _employee;
public virtual ICollection<Employee> Employee
{
get
{
if (_employee == null)
_employee = new HashSet<Employee>();
return _employee;
}
private set
{
_employee = new HashSet<Employee>(value);
}
}
}
以上写法没问题 在Employee类中增加构造函数
private Employee()
{
}
查询出来的employee中info属性值为空
可以加分的 我有25财富 可以都给你 展开
{
public Guid Id { get; set; }
public string Name { get; set; }
HashSet<Info> _info;
public virtual ICollection<Info> Infos
{
get
{
if (_info == null)
_info = new HashSet<Info>();
return _info;
}
private set
{
_info = new HashSet<Info>(value);
}
}
}
public class Info
{
public Guid Id { get; set; }
public string Department { get; set; }
public string Duty { get; set; }
HashSet<Employee> _employee;
public virtual ICollection<Employee> Employee
{
get
{
if (_employee == null)
_employee = new HashSet<Employee>();
return _employee;
}
private set
{
_employee = new HashSet<Employee>(value);
}
}
}
以上写法没问题 在Employee类中增加构造函数
private Employee()
{
}
查询出来的employee中info属性值为空
可以加分的 我有25财富 可以都给你 展开
2个回答
展开全部
设为私有的有意义吗,私有的就只能在本类中调用
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询