Я уже 3 дня склоняю голову над следующим запросом linq и не могу заставить его работать.
var measures = (
from header in session.Query<MeasureHeader>()
where headerIds.Contains(header.MeasureHeaderId)
select new
{
VehicleId = header.Vehicle.VehicleId,
VehicleName = header.Vehicle.Name,
VehicleExternalReference = header.Vehicle.ExternalReference,
LastMeasure = header.DateTime,
Lat = header.Langitude,
Long = header.Longitude,
Location = header.Location,
GroundSpeed = header.GroundSpeed,
GroudCourse = header.GroundCourse,
MeasureHeaderId = header.MeasureHeaderId,
DeviceId = header.Device.DeviceId,
Measures = (
from b in header.MeasureBodies
select new
{
b.Channel,
b.Value
}
)
}).ToList();
Когда я выполняю запрос, я получаю следующее исключение:
System.ArgumentException occurred
Message="Argument type 'System.Linq.IQueryable`1[<>f__AnonymousType0`2[System.Int32,System.Double]]' does not match the corresponding member type 'System.Collections.Generic.IEnumerable`1[<>f__AnonymousType0`2[System.Int32,System.Double]]'"
Source="System.Core"
StackTrace:
at System.Linq.Expressions.Expression.ValidateNewArgs(ConstructorInfo constructor, ReadOnlyCollection`1& arguments, ReadOnlyCollection`1 members)
at System.Linq.Expressions.Expression.New(ConstructorInfo constructor, IEnumerable`1 arguments, IEnumerable`1 members)
at Remotion.Data.Linq.Parsing.ExpressionTreeVisitor.VisitNewExpression(NewExpression expression)
at Remotion.Data.Linq.Parsing.ExpressionTreeVisitor.VisitExpression(Expression expression)
at Remotion.Data.Linq.Parsing.ExpressionTreeVisitors.SubQueryFindingExpressionTreeVisitor.VisitExpression(Expression expression)
at Remotion.Data.Linq.Parsing.ExpressionTreeVisitors.SubQueryFindingExpressionTreeVisitor.ReplaceSubQueries(Expression expressionTree, MethodCallExpressionNodeTypeRegistry nodeTypeRegistry)
at Remotion.Data.Linq.Parsing.Structure.IntermediateModel.ExpressionResolver.GetResolvedExpression(Expression unresolvedExpression, ParameterExpression parameterToBeResolved, ClauseGenerationContext clauseGenerationContext)
at Remotion.Data.Linq.Parsing.Structure.IntermediateModel.SelectExpressionNode.<>c__DisplayClass1.<GetResolvedSelector>b__0(ExpressionResolver r)
at Remotion.Data.Linq.Parsing.Structure.IntermediateModel.ResolvedExpressionCache`1.GetOrCreate(Func`2 generator)
at Remotion.Data.Linq.Parsing.Structure.IntermediateModel.SelectExpressionNode.GetResolvedSelector(ClauseGenerationContext clauseGenerationContext)
at Remotion.Data.Linq.Parsing.Structure.IntermediateModel.SelectExpressionNode.ApplyNodeSpecificSemantics(QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
at Remotion.Data.Linq.Parsing.Structure.IntermediateModel.MethodCallExpressionNodeBase.Apply(QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
at Remotion.Data.Linq.Parsing.Structure.QueryParser.ApplyAllNodes(IExpressionNode node, ClauseGenerationContext clauseGenerationContext)
at Remotion.Data.Linq.Parsing.Structure.QueryParser.GetParsedQuery(Expression expressionTreeRoot)
at NHibernate.Linq.NhRelinqQueryParser.Parse(Expression expression) in d:\CSharp\NH\nhibernate\src\NHibernate\Linq\NhRelinqQueryParser.cs:line 60
InnerException:
В основном я хочу выбрать подмножество свойств из MeasureHeader (родительский) и подмножество Measurebody MeasureHeader (дочерний).Возможно ли это с провайдером NHibernate 3.0 Linq?
Справка высоко ценится!*:
В списке выбора можно указать только одно выражение, если подзапрос не введен с EXISTS.
В базе данных был выполнен следующий запрос:
select vehicle1_.VehicleId as col_0_0_,
vehicle1_.Name as col_1_0_,
vehicle1_.ExternalReference as col_2_0_,
measurehea0_.DateTime as col_3_0_,
measurehea0_.Langitude as col_4_0_,
measurehea0_.Longitude as col_5_0_,
measurehea0_.Location as col_6_0_,
measurehea0_.GroundSpeed as col_7_0_,
measurehea0_.GroundCourse as col_8_0_,
measurehea0_.MeasureHeaderId as col_9_0_,
device2_.DeviceId as col_10_0_,
(select measurebod3_.Channel,
measurebod3_.Value
from dbo.tblMeasureBodies measurebod3_
where measurehea0_.MeasureHeaderId = measurebod3_.MeasureHeaderId) as col_11_0_
from dbo.tblMeasureHeaders measurehea0_
left outer join dbo.tblVehicles vehicle1_
on measurehea0_.VehicleId = vehicle1_.VehicleId
left outer join dbo.sysDevices device2_
on measurehea0_.DeviceId = device2_.DeviceId
where measurehea0_.MeasureHeaderId in (240857 /* @p0 */,240809 /* @p1 */,240811 /* @p2 */,240816 /* @p3 */,
240817 /* @p4 */,240822 /* @p5 */,240819 /* @p6 */,117202 /* @p7 */,
240808 /* @p8 */,240805 /* @p9 */,240796 /* @p10 */,240797 /* @p11 */,
240799 /* @p12 */,240798 /* @p13 */,240818 /* @p14 */,29071 /* @p15 */,
240780 /* @p16 */,240778 /* @p17 */,240779 /* @p18 */,240783 /* @p19 */,
240789 /* @p20 */,240788 /* @p21 */,240801 /* @p22 */,240804 /* @p23 */,
240803 /* @p24 */,240814 /* @p25 */,240782 /* @p26 */,240786 /* @p27 */,
240781 /* @p28 */,240790 /* @p29 */,240810 /* @p30 */,240784 /* @p31 */,
240785 /* @p32 */,240792 /* @p33 */,15 /* @p34 */,240815 /* @p35 */,
240787 /* @p36 */,240791 /* @p37 */,140709 /* @p38 */,140697 /* @p39 */,
240793 /* @p40 */,240794 /* @p41 */,240795 /* @p42 */,240800 /* @p43 */,
240802 /* @p44 */,240807 /* @p45 */,240806 /* @p46 */)
Edit2: Просто чтобы все знали, мы перешли на HQL для этого конкретного запроса, так как кажется, что это невозможно сделать с использованием текущего провайдера Linq.Если у кого-то есть предложение, ответьте!