我想指出的是,我仍然没有涵盖< map/>的所有选项,
还有更多选择(尽管IDictionary< K,IList< V >>不是
对于可能需要映射的有问题的SQL语句,可以进行映射.
I would like to point out that I have still not covered all the options for <map/>, there
are even more options (Although, IDictionary<K, IList<V >> is not something that is
possible to map, for the problematic SQL statements that would be required to do so).
您将需要一些中介实体/组件.我可能会有一个ProjectAssignment实体来打破用户,项目和角色之间的纽带关系-随着时间的流逝,它可能会增加额外的属性(例如您想跟踪随时间变化的分配,因此得到StartDate
和EndDate
属性).
You'll need some intermediary entity/component. I'd probably have a ProjectAssignment entity to break up the nary association between User, Project and Role - it will probably grow extra attributes as time goes on (say you want to track changes to the assignments over time, so it gets StartDate
and EndDate
properties).
类似的东西:
public class User {
// ... other attributes etc.
public virtual ISet<ProjectAssignment> Assignments {get;set;}
}
public class Project {
// ... other attributes etc.
public virtual ISet<ProjectAssignment> Assignments {get;set;}
}
public class Role {
// ... other attributes etc.
}
public class ProjectAssignment
{
public virtual Int64 {get;set;}
public virtual User User {get;set;}
public virtual Project Project {get;set;}
public virtual Role Role {get;set;}
// ... other attributes etc.
}
我只是将ProjectAssignment本身映射为持久性类,将User.Assignments集合映射为正常的一对多类型.最后,我将添加一种将详细信息提取到字典中的方法(如果使用的是Framework v3.5,则可能是ILookup):
I'd just map the ProjectAssignment as a persistent class in its own right, and the User.Assignments collections as a normal one-to-many of whatever flavour. Finally, I'd add a method to extract the details into a dictionary (or probably an ILookup if you're using Framework v3.5): something like:
ILookup<Project, Role> GetRolesByProject() {
return Assignments.ToLookup(x => x.Project, x => x.Role);
}
这篇关于如何映射具有IList值的IDictionary?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!