3
나는 C#을 부분적으로NHibernate에 유착 문제
DECLARE @date DATETIME = NULL;
SELECT
ER.Id
, ER.DocumentDate
FROM
ExpenseReport ER
WHERE
ER.PeriodFrom >= COALESCE(@date, ER.PeriodFrom)
OR ER.PeriodTo <= COALESCE(@date, ER.PeriodTo);
그래서 NHibernate에 다음과 같은 SQL 쿼리를 표현하기 위해 노력하고 나는 다음과 같은 클래스가 수행 엔티티
- 을 : ExpenseReport 내 검색에 대한
- 은 별도의 클래스입니다
코드 조각 :
IQueryOver<ExpenseReport>
var q = SessionProvider.QueryOver<ExpenseReport>();
내가 조금 NHibernate에와 지금 손실 나는 지금 검색 매개 변수를 할당 그래서
// ----- Entity class.
public partial class ExpenseReport
{
public Nullable<System.DateTime> PeriodFrom { get; set; }
// many other properties
}
// ----- Search parameter class.
public class SearchParameters
{
public Nullable<System.DateTime> DateFrom { get; set; }
// many other properties
}
, .... 어떻게 지금해야합니까?
// left side
var left = Projections.Property<ExpenseReport>(ti => ti.PeriodFrom);
// right side
var right = Projections.SqlFunction("COALESCE"
, NHibernateUtil.DateTime
, Projections.Constant(search.DateFrom, NHibernateUtil.DateTime)
, Projections.Property<ExpenseReport>(ti => ti.PeriodFrom)
);
// the restriction using the GeProperty, taking two IProjections
var restriction = Restrictions.GeProperty(left, right);
// finally - our query get its WHERE
q.Where(restriction);
그래서, 우리는 먼저 두 개의 예측을 만듭니다
q.And(/*** I AM STUCK HERE **/)
와우! 이렇게 쉬운 당신의 포스트를 읽는 경우에 .... 나중에 검사해야 할 것이다 :) –
중대한지도 ... 나는 화제에 조금 더 명확한 것을 얻기 위하여 희망에있는이 응답에 관해서는 속행 질문을 배치했다 : http : //stackoverflow.com/questions/29221666/nhibernate-comparison-constraint-to-a-coasedced-date – beauXjames
* 질문을 올바르게 읽은 경우에 대비하여 ... * –