Hello all!
I was wondering if something like a predicate builder would work with LLBLGen.
Here is the code I am referring to:
http://www.albahari.com/nutshell/predicatebuilder.html
I created a method in my service layer that takes an expression that filters out the data. It works fine when I just pass in an expression as a lambda. When I start to use the Predicate builder I get the following:
Exception: System.ArgumentException
Message: "Expression of type 'System.Boolean' cannot be invoked"
Stack Trace:
at System.Linq.Expressions.Expression.Invoke(Expression expression, IEnumerable1 arguments)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleInvocationExpression( InvocationExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder. HandleBinaryExpressionArithmeticOrBitOperator(BinaryExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleLambdaExpression(LambdaExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleWhereExpression(WhereExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle, SelectExpression newInstance)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleSelectExpression(SelectExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.HandleExpressionTree(Expression expression)
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.Execute(Expression expression)
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute(Expression expression)
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery
1.Execute()
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery1.SD.LLBLGen.Pro.LinqSupportClasses .ILLBLGenProQuery.Execute[TResult]()
at TrackerPlus.Business.Views.VehicleView.GetVehiclesByExpression(Expression
1 whereClause) in C:\Projects\TrackerPlus\TrackerPlus.Business\Views\VehicleView.cs:line 46
... my stuff that calls your stuff was here
I am using v2.6 Final, Released on June 6th, 2008. Targeting .NET 3.5 adapter model.
Is there a different way of doing this? I also tried the following variant of the And<> extension method with the following result:
public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> expr1,
Expression<Func<T, bool>> expr2)
{
//var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
return Expression.Lambda<Func<T, bool>>
(Expression.And(expr1.Body, expr2.Body), expr1.Parameters);
}
Exception: ORMQueryExecutionException
InnerException: An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as \"\" or [] are not allowed. Add a name or single space as the alias name.
QueryExecuted:
Query: SELECT DISTINCT [LPLA_1].[VehicleId], [LPLA_1].[VIN] AS [Vin], [LPLA_1].[VehicleStatusId], [LPLA_1].[StickerNumber], [LPLA_1].[VehicleNumber], [LPLA_1].[Description], [LPLA_1].[MakeId], [LPLA_1].[ModelId], [LPLA_1].[Year], [LPLA_1].[VehicleTypeId], [LPLA_1].[OwnedBy], [LPLA_1].[AssignedTo], [LPLA_1].[LessorId], [LPLA_1].[LeaseNumber], [LPLA_1].[LeaseYears], [LPLA_1].[LeaseStart], [LPLA_1].[LeaseExpiration], [LPLA_1].[LeaseMiles], [LPLA_1].[PurchasePrice], [LPLA_1].[Residual], [LPLA_1].[LeasePayment], [LPLA_1].[LeaseEndCharge], [LPLA_1].[EmployeeAssigned], [LPLA_1].[PolicyRemovalDate], [LPLA_1].[RegistrationDate], [LPLA_1].[ExpirationDate], [LPLA_1].[DecalWeight], [LPLA_1].[PurchaseDate], [LPLA_1].[PlateNumber], [LPLA_1].[StateCode], [LPLA_1].[RegAddress], [LPLA_1].[RegCity], [LPLA_1].[RegZip], [LPLA_1].[FuelTypeId], [LPLA_1].[Created], [LPLA_1].[Updated], [LPLA_1].[AddedToPolicy]
FROM [dbo].[Vehicle] [LPLA_1] WHERE ( ( ( ( ( [].[LPFA_1] = @LPFA_11)))))
Parameter: @LPFA_11 : Boolean. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: True.
My Service Layer call:
public EntityCollection<VehicleEntity> GetVehiclesByExpression(Expression<Func<VehicleEntity, bool>> whereClause)
{
using (IDataAccessAdapter adapter = this._adapter.Create())
{
LinqMetaData metaData = new LinqMetaData(adapter);
return metaData.Vehicle
.Where<VehicleEntity>(whereClause)) as ILLBLGenProQuery)
.Execute<EntityCollection<VehicleEntity>>())
}
}
I do some prefetching of other related entities but ommitted that code to simplify the question.
Any thoughts?