English 中文(简体)
学历 独立时通过加入和增加条件
原标题:QueryOver by join and add conditions by Independent if

我在Nhibernate有3名Join QueryOver。

The Person class has a association by Identity class (one-to-one) Code is a field of Person class and FirstName is a field of Identity class.

var q = SessionInstance.QueryOver<Person>()
        .Where(p => p.Code.IsLike(code,MatchMode.Start))
        .Full.JoinQueryOver(p => p.Identity);

if (!String.IsNullOrEmpty(firstName))
   q = q.Where(i => i.FirstName.IsLike(firstName, MatchMode.Anywhere));

return q.List<Person>();

结果是正确的,但存在问题。 搜查并不包括个人类别法典领域无价值物品。 我更正如下。

var q = SessionInstance.QueryOver<Person>()
        .Full.JoinQueryOver(p => p.Identity);

if (!String.IsNullOrEmpty(Code))
   q = q.Where(i => i.Person.Code.IsLike(code, MatchMode.Start));

if (!String.IsNullOrEmpty(firstName))
   q = q.Where(i => i.FirstName.IsLike(firstName, MatchMode.Anywhere));

return q.List<Person>();

现在我对这一信息有误:

不能解决财产问题:身份。 Code of: MyName Space.Domain.Entities.Identity

在两组之间合并的询问中,如果是,如何增加两个条件(如果有的话)。

(if parameter != null)

最佳回答
Identity identityAlias = null;
var q = SessionInstance.QueryOver<Person>()
        .Full.JoinAlias(p => p.Identity, () => identityAlias);

if (!String.IsNullOrEmpty(code))
   q.Where(p => p.Code.IsLike(code, MatchMode.Start));

if (!String.IsNullOrEmpty(firstName))
   q.Where(() => identityAlias.FirstName.IsLike(firstName, MatchMode.Anywhere));

var q = SessionInstance.QueryOver<Person>();

if (!String.IsNullOrEmpty(code))
    q.Where(p => p.Code.IsLike(code, MatchMode.Start));

if (!String.IsNullOrEmpty(firstName))
    q.Full.JoinQueryOver(p => p.Identity)
        .Where(i => i.FirstName.IsLike(firstName, MatchMode.Anywhere));
问题回答

暂无回答




相关问题
nHibernate one-to-many inserts but doesnt update

Instead of getting into code, I have a simple question. Default behavior for a simple one-to-many is that it inserts the child record then updates the foreign key column with the parent key. Has ...

How Do I copy an existing nhibernate object as a new object?

I a persisted NHibernate object that I would like to repersist as a new entity. How do I get NHibernate to save this object as if it was a new? I am thinking I might create a session interceptor to ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

NHibernate Search in a List using ICriteria

I have my class X : public class ClassX { public virtual IList<ClassY> ListY { get; set; } ... } My ClassX mapping (using Fluent) ... HasMany<ClassX>(x => x.ListY ) ....

热门标签