非外键属性上的Fluent Nhibernate联接

非外键属性上的Fluent Nhibernate联接,nhibernate,orm,fluent-nhibernate,foreign-keys,left-join,Nhibernate,Orm,Fluent Nhibernate,Foreign Keys,Left Join,我到处都找不到这个,但它看起来很琐碎。所以,如果这是重复的,请原谅 我有点像: public class Doctor : Entity { ...some other properties here... public virtual string Email { get; set; } } public class Lawyer : Entity { ...some other properties here... public virtual string

我到处都找不到这个,但它看起来很琐碎。所以,如果这是重复的,请原谅

我有点像:

public class Doctor : Entity
{
    ...some other properties here...
    public virtual string Email { get; set; }
}

public class Lawyer : Entity
{
    ...some other properties here...
    public virtual string Email { get; set; }
}
我想返回律师表中没有电子邮件匹配的所有医生,如:

select * from Doctors d
where d.Email not in
(select l.Email from Lawyers l where l.Email is not null)
或使用联接:

select d.* from Doctors d
left join Lawyers l on l.Email = d.Email
where l.Email is null
问题是电子邮件当然没有设置为外键。我在映射到律师的医生实体上没有映射属性

到目前为止,我所尝试的:

ICriteria criteria = Session.CreateCriteria(typeof(Doctor))
    .CreateAlias("Lawyers.Email", "LawyerEmail", JoinType.LeftOuterJoin)
    .Add(Restrictions.IsNull("LawyerEmail"));

return criteria.List<Doctor>();
ICriteria标准=Session.CreateCriteria(医生类型))
.CreateAlias(“Lawyers.Email”、“LawyerEmail”、JoinType.LeftOuterJoin)
.Add(Restrictions.IsNull(“律师电子邮件”));
返回条件。List();
但是,我得到一个“无法解析MyPlatform.MyNamespace.Doctor的属性”错误。如何设置我的DoctorMap并调整标准以实现这一点,有什么想法吗


NHibernate for the loss…..实体框架for the win….

我们可以通过一个称为子查询的功能实现这一点:

// a inner SELECT to return all EMAILs from Lawyer table
var subQuery = DetachedCriteria.For<Lawyer>()
    .SetProjection(Projections.Property("Email"));

// the root SELECT to get only these Doctors
var criteria = session.CreateCriteria<Doctor>();

// whos email is not in the sub SELECT
criteria.Add(Subqueries.PropertyNotIn("Email", subQuery));

// get first 10
var result = criteria
    .SetMaxResults(10)
    .SetFirstResult(0) // paging
    .List<Doctor>();
//用于返回律师表中所有电子邮件的内部选择
var subQuery=DetachedCriteria.For()
.SetProjection(Projections.Property(“电子邮件”));
//根目录选择仅获取这些医生
var-criteria=session.CreateCriteria();
//谁的电子邮件不在子选择中
添加(subquerys.PropertyNotIn(“电子邮件”,subQuery));
//获得前10名
var结果=标准
.SetMaxResults(10)
.SetFirstResult(0)//分页
.List();

很棒,享受NHibernate,很棒的工具:)