我有一个类似于这样的表结构:
User
-------
UserId
UserName
{several additional fields}
Program
-------
ProgramId
ProgramName
UserId
{several additional fields}
College
-------
CollegeId
CollegeName
{several additional fields}
College_Users
-------------
CollegeId
UserId
每个程序只与一个用户相关联,但每个学院可能连接到多个用户。
我有一个如下所示的类结构:
public abstract class LoggedInUser {
public virtual int UserId { get; set; }
public virtual string UserName { get; set; }
}
public class LoggedInProgram : LoggedInUser {
public virtual int ProgramId { get; set; }
public virtual int ProgramName { get; set; }
}
public class LoggedInCollege : LoggedInUser {
public virtual int CollegeId { get; set; }
public virtual int CollegeName { get; set; }
}
我已经能够通过使用以下映射来使程序正常工作:
public class LoggedInUserMap : ClassMap<LoggedInUser> {
public LoggedInUserMap() {
Table("Users");
Id(x => x.UserId).Column("UserId");
Map(x => x.UserName);
}
}
public class LoggedInProgramMap : SubclassMap<LoggedInProgram> {
public LoggedInProgramMap() {
Table("Program");
KeyColumn("UserId");
Map(x => x.ProgramId);
Map(x => x.ProgramName);
}
}
但是,我不能弄清楚如何让College映射到这个类结构。
我可以写一个简单的查询,它给我想要的结果,但无法弄清楚如何编写一个能给我相同结果的映射。查询如下所示:
select c.CollegeId
, c.CollegeName
, u.UserId
, u.UserName
from College c
inner join dbo.College_Users cu on c.CollegeId = cu.CollegeId
inner join Users u on cu.UserId = u.UserId
所以我的两部分问题是,甚至可以让FluentNhibernate进行这种映射,如果是这样,我该怎么做?