C# 实体';的导航属性是哈希集和can';不受控制
我有一个名为Employee的实体,它有一个名为Groups的导航属性 组映射到具有名称属性的组实体 为了设置关系数据,我实现了这个问题的答案: 我为员工设立了一个实体,该实体还包括他们的团体:C# 实体';的导航属性是哈希集和can';不受控制,c#,asp.net,entity-framework,C#,Asp.net,Entity Framework,我有一个名为Employee的实体,它有一个名为Groups的导航属性 组映射到具有名称属性的组实体 为了设置关系数据,我实现了这个问题的答案: 我为员工设立了一个实体,该实体还包括他们的团体: <asp:EntityDataSource ID="GroupsByEmployeeSource" runat="server" ConnectionString="name=SafetyContext" DefaultContainerName="SafetyContext" EnableDe
<asp:EntityDataSource ID="GroupsByEmployeeSource" runat="server" ConnectionString="name=SafetyContext" DefaultContainerName="SafetyContext" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" EntitySetName="Employees" Include="Groups" Where="it.[EID] == @EmpID">
<WhereParameters>
<asp:ControlParameter Name="EmpID" Type="Int32" ControlID="GridView1" PropertyName="SelectedDataKey.Value" />
</WhereParameters>
</asp:EntityDataSource>
我意识到这是因为组是一个哈希集。在我查看实体对象的生成代码后,这就更有意义了:
public partial class Employee
{
public Employee()
{
this.Employee_Action = new HashSet<Employee_Action>();
this.Groups = new HashSet<Group>();
}
public long EID { get; set; }
public string Manager { get; set; }
public string Location { get; set; }
public string Name { get; set; }
public string SESA { get; set; }
public virtual ICollection<Employee_Action> Employee_Action { get; set; }
public virtual ICollection<Group> Groups { get; set; }
}
公共部分类员工
{
公职人员()
{
this.Employee_Action=new HashSet();
this.Groups=newhashset();
}
公共长EID{get;set;}
公共字符串管理器{get;set;}
公共字符串位置{get;set;}
公共字符串名称{get;set;}
公共字符串SESA{get;set;}
公共虚拟ICollection员工_操作{get;set;}
公共虚拟ICollection组{get;set;}
}
在构造函数中,导航属性被创建为哈希集。不幸的是,在阅读了hashset之后,我意识到它们只能被迭代。所以现在我有了一个导航属性,我基本上无法通过通常将数据绑定到控件的方式访问它
我不确定访问导航属性需要做什么。我是否将生成的代码更改为Hashset以外的内容?有没有办法#Eval()组并实际获取组的属性而不是哈希集的属性?我是不是应该在“评估电话”中加入团队?对于如何获取实体的导航属性所表示的实体,我非常困惑。如果答案是以编程方式进行,那么我应该处理什么事件 既然组是组项目的集合,那么您实际上想在列中显示什么?收藏中的第一组?或者集合中的所有组都用逗号分隔
你可以试试
Groups.First().Name
或
string.Join(“,”,Groups.Select(g=>g.Name.ToArray())
public partial class Employee
{
public Employee()
{
this.Employee_Action = new HashSet<Employee_Action>();
this.Groups = new HashSet<Group>();
}
public long EID { get; set; }
public string Manager { get; set; }
public string Location { get; set; }
public string Name { get; set; }
public string SESA { get; set; }
public virtual ICollection<Employee_Action> Employee_Action { get; set; }
public virtual ICollection<Group> Groups { get; set; }
}