在Nhibernate中导致这个1 = 0的原因
SELECT
this_.LoanId as LoanId89_0_,
this_.BranchId as BranchId89_0_,
FROM
dbo.Loan this_
WHERE
this_.LoanId in (
SELECT
this_0_.LoanId as y0_
FROM
dbo.MyEntity this_0_
WHERE
this_0_.MyEntityId = 795
)
and 1=0
ORDER BY
this_.LoanNumber asc;
我正在尝试检索一些记录,而Nhibernate在AND子句中将其转换为1 = 0
Loan.cs
public Loan() : base()
{
this.Loanid = null; //int32 type
this.Branchid = null; //int32 type
}
这是小版Loan Class的样子。 由于子查询,它执行WHERE。它选择ID因为GetIQueryOverForLoanSearch.It只使用Projections和AliasToBean(SearchResult)选择所有列。我只是无法理解或弄清楚1 = 0的来源? 还有一些子查询正在进行中。这只是一个非常小的版本
var subQuery = QueryOver.Of<MyEntity>().Where(x => x.MyEntityId == entityId).Select(x => x.LoanId);
var loans = GetIQueryOverForLoanSearch(manager.Session.GetISession(), false).WithSubquery.WhereProperty(x => x.Id).In(subQuery).OrderBy(x => x.LoanNumber).Asc.List<SearchResult>();
private static IQueryOver<Loan, Loan> GetIQueryOverForLoanSearch(ISession session, bool setMaxSearchResults = true)
{
SearchResult lr = null;
Loan l = null;
var queryOver = session.QueryOver(() => l).Select(Projections.Property(() => l.Id).WithAlias(() => lr.LoanId)).TransformUsing(Transformers.AliasToBean<SearchResult>());
return queryOver;
}
我应该查看DataStructure或标准吗?
答案 0 :(得分:1)
那是完整的代码吗?因为当空1 = 0
存在时我看到悬空Restrictions.Disjunction
,但我在那里看不到任何一个。