Repository navigation
Description
query using gears of war model:
ctx.Weapons.Select(w => w.SynergyWith).OrderBy(g => g.IsAutomatic)query model:
from Weapon w in DbSet<Weapon>
join Weapon w.SynergyWith in DbSet<Weapon>
on Property([w], "SynergyWithId") equals (Nullable<int>)Property([w.SynergyWith], "Id") into w.SynergyWith_group
from Weapon w.SynergyWith in
(from Weapon w.SynergyWith_groupItem in [w.SynergyWith_group]
select [w.SynergyWith_groupItem]).DefaultIfEmpty()
order by (bool)?[w.SynergyWith] | ?[w.SynergyWith] | [w.SynergyWith]?.IsAutomatic == True? == True? asc
select [w.SynergyWith]
query plan:
(QueryContext queryContext) => IEnumerable<Weapon> _InterceptExceptions(
|__ source: IEnumerable<Weapon> _Select(
| |__ source: IOrderedEnumerable<TransparentIdentifier<TransparentIdentifier<ValueBuffer, IEnumerable<Weapon>>, Weapon>> _OrderBy(
| | |__ source: IEnumerable<TransparentIdentifier<TransparentIdentifier<ValueBuffer, IEnumerable<Weapon>>, Weapon>> _SelectMany(
| | | |__ source: IEnumerable<TransparentIdentifier<ValueBuffer, IEnumerable<Weapon>>> _GroupJoin(
| | | | |__ outer: IEnumerable<ValueBuffer> ProjectionQuery(
| | | | | |__ queryContext: queryContext,
| | | | | |__ entityType: EntityType: Weapon),
| | | | |__ inner: IEnumerable<Weapon> EntityQuery(
| | | | | |__ queryContext: queryContext,
| | | | | |__ entityType: EntityType: Weapon,
| | | | | |__ key: Key: Weapon.Id PK,
| | | | | |__ materializer: (IEntityType entityType | MaterializationContext materializationContext) =>
| | | | | | {
| | | | | | instance = new Weapon()
| | | | | | instance.<Id>k__BackingField = int TryReadValue(ValueBuffer materializationContext.get_ValueBuffer(), 0, Weapon.Id)
| | | | | | instance.<AmmunitionType>k__BackingField = Nullable<AmmunitionType> TryReadValue(ValueBuffer materializationContext.get_ValueBuffer(), 1, Weapon.AmmunitionType)
| | | | | | instance.<IsAutomatic>k__BackingField = bool TryReadValue(ValueBuffer materializationContext.get_ValueBuffer(), 2, Weapon.IsAutomatic)
| | | | | | instance.<Name>k__BackingField = string TryReadValue(ValueBuffer materializationContext.get_ValueBuffer(), 3, Weapon.Name)
| | | | | | instance.<OwnerFullName>k__BackingField = string TryReadValue(ValueBuffer materializationContext.get_ValueBuffer(), 4, Weapon.OwnerFullName)
| | | | | | instance.<SynergyWithId>k__BackingField = Nullable<int> TryReadValue(ValueBuffer materializationContext.get_ValueBuffer(), 5, Weapon.SynergyWithId)
| | | | | | return instance
| | | | | | },
| | | | | |__ queryStateManager: False),
| | | | |__ outerKeySelector: (ValueBuffer w) => Nullable<int> TryReadValue(w, 5, Weapon.SynergyWithId),
| | | | |__ innerKeySelector: (Weapon w.SynergyWith) => (Nullable<int>)int GetValueFromEntity(
| | | | | clrPropertyGetter: ClrPropertyGetter<Weapon, int>,
| | | | | entity: w.SynergyWith),
| | | | |__ resultSelector: (ValueBuffer w | IEnumerable<Weapon> w.SynergyWith_group) => TransparentIdentifier<ValueBuffer, IEnumerable<Weapon>> CreateTransparentIdentifier(
| | | | |__ outer: w,
| | | | |__ inner: w.SynergyWith_group)),
| | | |__ collectionSelector: (TransparentIdentifier<ValueBuffer, IEnumerable<Weapon>> t0) => IEnumerable<Weapon> DefaultIfEmpty(t0.Inner),
| | | |__ resultSelector: (TransparentIdentifier<ValueBuffer, IEnumerable<Weapon>> t0 | Weapon w.SynergyWith) => TransparentIdentifier<TransparentIdentifier<ValueBuffer, IEnumerable<Weapon>>, Weapon> CreateTransparentIdentifier(
| | | |__ outer: t0,
| | | |__ inner: w.SynergyWith)),
| | |__ expression: (TransparentIdentifier<TransparentIdentifier<ValueBuffer, IEnumerable<Weapon>>, Weapon> t1) => (bool)?t1.Inner | ?t1.Inner | t1.Inner?.IsAutomatic == True? == True?,
| | |__ orderingDirection: Asc),
| |__ selector: (TransparentIdentifier<TransparentIdentifier<ValueBuffer, IEnumerable<Weapon>>, Weapon> t1) => t1.Inner),
|__ contextType: TestModels.GearsOfWarModel.GearsOfWarContext,
|__ logger: DiagnosticsLogger<Query>,
|__ queryContext: queryContext)
exception:
Nullable object must have a value.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at lambda_method(Closure , TransparentIdentifier2 ) at System.Linq.EnumerableSorter2.ComputeKeys(TElement[] elements, Int32 count)
at System.Linq.EnumerableSorter1.Sort(TElement[] elements, Int32 count) at System.Linq.OrderedEnumerable1.d__1.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor1.EnumeratorExceptionInterceptor.MoveNext()
at System.Linq.Buffer1..ctor(IEnumerable1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at Microsoft.EntityFrameworkCore.TestUtilities.QueryAsserter1.d__181.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.EntityFrameworkCore.Query.QueryTestBase1.AssertQuery[TItem1](Func2 actualQuery, Func2 expectedQuery, Func2 elementSorter, Action2 elementAsserter, Boolean assertOrder, Int32 entryCount)
at Microsoft.EntityFrameworkCore.Query.GearsOfWarQueryTestBase`1.Double_order_by_on_nullable_bool_coming_from_optional_navigation()
at Microsoft.EntityFrameworkCore.Query.GearsOfWarQueryInMemoryTest.Double_order_by_on_nullable_bool_coming_from_optional_navigation()
Activity
maumar commentedon Jun 7, 2018
problem here is that in order by clause we are converting
bool?ordering back toboolto match the type, which can break if the ordering resolves to null. We could convert to ordering == true instead, but need to investigate if that doesn't have side-effects for other scenarios (different data returned)NavigationRewritingExpressionVisitor -> CompensateForNullabilityDifference
Query: Add regression test for #12295
smitpatel commentedon Dec 6, 2019
Working correctly in 3.1
Query: Add regression test for #12295