Product productAlias = null;
Session sessionAlias = null;
Slot slotAlias = null;
Price priceAlias = null;
var queryOver = session.QueryOver<Slot>(() => slotAlias)
.JoinAlias(() => slotAlias.Session,() => sessionAlias)
.JoinAlias(() => sessionAlias.Product,() => productAlias);
if (productGuid.HasValue)
{
var productEntity = session.Query<Product>().FirstOrDefault(x => x.Guid == productGuid.Value);
queryOver = queryOver.Where(() => productAlias.Id == productEntity.Id);
}
if (onlyAvailable)
{
queryOver = queryOver.Where(() => slotAlias.StartDate >= DateTimeOffset.UtcNow.AddMinutes(productAlias.Duration));
}
queryOver.List();
このクエリを実行すると、TargetInvocationExceptionが発生します。内部メッセージでは、slotAlias.StartDate(Line 18、onlyAvailable if節内)のNullReferenceExceptionです。TargetInvocationExceptionがJoinAliasのNhibernate QueryOverの場合
if節とこのような複数のWhere節でエイリアスを使用すると何か問題はありますか?
のStackTrace:この行では
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at lambda_method(Closure)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at NHibernate.Impl.ExpressionProcessor.FindValue(Expression expression)
at NHibernate.Impl.ExpressionProcessor.ProcessSimpleExpression(Expression left, Expression right, ExpressionType nodeType)
at NHibernate.Impl.ExpressionProcessor.ProcessSimpleExpression(BinaryExpression be)
at NHibernate.Impl.ExpressionProcessor.ProcessBinaryExpression(BinaryExpression expression)
at NHibernate.Impl.ExpressionProcessor.ProcessExpression(Expression expression)
at NHibernate.Criterion.QueryOver`2.NHibernate.IQueryOver<TRoot,TSubType>.Where(Expression`1 expression)
at Fullseats.Database.Repositories.Repository.GetSlots(Int32 limit, Int32 offset, Nullable`1 operatorGuid, Nullable`1 productGuid, Nullable`1 from, Nullable`1 to, Boolean onlyAvailable) in C:\Users\erkin\Desktop\FullSeats\Fullseats.Api\Fullseats.Database\Repositories\Repository.cs:line 455
at Fullseats.Server.Core.Services.ProductService.GetSlots(Guid productGuid, PaginationQuery paginationQuery) in C:\Users\erkin\Desktop\FullSeats\Fullseats.Api\Fullseats.Server\Core\Services\ProductService.cs:line 63
at Fullseats.Server.Modules.ProductModule.GetSlotsForProduct(Object arg) in C:\Users\erkin\Desktop\FullSeats\Fullseats.Api\Fullseats.Server\Modules\ProductModule.cs:line 224
at CallSite.Target(Closure , CallSite , Func`2 , Object)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at Nancy.Routing.Route.<>c__DisplayClass4.<Wrap>b__3(Object parameters, CancellationToken context)
あなたはthis--を行うことができる必要がありますが、完全な例外テキストを投稿することができますか? –
[this JIRA issue](https://nhibernate.jira.com/browse/NH-3822)に関連しているのでしょうか –
@AndrewWhitaker productAlias.Durationを使用すると問題が発生します。私はちょうどそこに任意の番号を使用する場合は動作します。 – erkinyldz