- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
ToQueryText Error
Joined: 27-Jul-2005
Version 4.1 (March 12th, 2014) Runtime version v4.0.30319 Template group Self Servicing .Net 4.5.1 SQL Server version 2012 (11.0.3128.0)
I keep receiving an error when I try to use the ToQueryText method. If I take the line with that in it, the following code works fine and returns the correct data.
var labs = new LabCollection(); var predForLabs = new PredicateExpression(); var myCreator = new SD.LLBLGen.Pro.DQE.SqlServer.SqlServerSpecificCreator(); predForLabs.DatabaseSpecificCreator = myCreator; predForLabs.Add(LabFields.Name == "LabName1");
var x = predForLabs.ToQueryText();
labs.GetMulti(predForLabs);
I know I am not using the returned value of the ToQueryText method in the code, I am just using this as sample/test code to get this working for use in other code. I must be missing a reference to something but I can't see what.
I am referencing these Dlls:
C:\Program Files (x86)\Solutions Design\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\CompiledRuntimeLibraries\SD.LLBLGen.Pro.DQE.SqlServer.dll
C:\Program Files (x86)\Solutions Design\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\CompiledRuntimeLibraries\NET4.5\SD.LLBLGen.Pro.ORMSupportClasses.dll
When the code hits the ToQueryText method I receive this error:
SD.LLBLGen.Pro.ORMSupportClasses.ORMGeneralOperationException was unhandled by user code HResult=-2146232832 Message=None of the factories in the list of '' were found. Please check machine.config and the .NET version your application is running on. Source=SD.LLBLGen.Pro.ORMSupportClasses RuntimeBuild=02272014_WithAsync RuntimeVersion=4.1.0.0 StackTrace: at SD.LLBLGen.Pro.ORMSupportClasses.DbProviderFactoryInfo.get_FactoryToUse() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Persistence\DbProviderFactoryInfo.cs:line 241 at SD.LLBLGen.Pro.DQE.SqlServer.SqlServerSpecificCreator.get_FactoryToUse() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\SqlServerDQE\SqlServerSpecificCreator.cs:line 559 at SD.LLBLGen.Pro.ORMSupportClasses.DbSpecificCreatorBase.CreateParameterInstance(String parameterType) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Persistence\DbSpecificCreatorBase.cs:line 1207 at SD.LLBLGen.Pro.ORMSupportClasses.DbSpecificCreatorBase.CreateParameter(String parameterType, Int32 size, ParameterDirection direction, Boolean isNullable, Byte precision, Byte scale, Object value) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Persistence\DbSpecificCreatorBase.cs:line 137 at SD.LLBLGen.Pro.DQE.SqlServer.SqlServerSpecificCreator.CreateParameter(String parameterType, Int32 size, ParameterDirection direction, Boolean isNullable, Byte precision, Byte scale, Object value) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\SqlServerDQE\SqlServerSpecificCreator.cs:line 144 at SD.LLBLGen.Pro.ORMSupportClasses.DbSpecificCreatorBase.CreateParameter(IEntityFieldCore field, IFieldPersistenceInfo persistenceInfo, ParameterDirection direction, Object valueToSet) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Persistence\DbSpecificCreatorBase.cs:line 199 at SD.LLBLGen.Pro.ORMSupportClasses.FieldCompareValuePredicate.ToQueryText(Boolean inHavingClause) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\QueryApiElements\FieldCompareValuePredicate.cs:line 288 at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Boolean inHavingClause) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\QueryApiElements\PredicateExpression.cs:line 226 at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\QueryApiElements\PredicateExpression.cs:line 179 at SampleAPI.Controllers.LabsObjWithParameterController.Get(String FirstLetter) in c:\Development\Tests\SampleMarch2014\API\SampleAPI\Controllers\LabsObjWithParameterController.cs:line 35 at lambda_method(Closure , Object , Object[] ) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken) InnerException:
You should insert persistence information into the predicate expression objects. That is: the real names they should have in the generate SQL. That info is only known by your generated DynamicQueryEngine. So, at your generated project, extend the CommonDaoBase this way:
using SD.LLBLGen.Pro.DQE.SqlServer;
using SD.LLBLGen.Pro.ORMSupportClasses;
namespace <yourRootNamespace>.DaoClasses
{
public partial class CommonDaoBase
{
public string GetQuery(IPredicateExpression predicate)
{
var dqe = new DynamicQueryEngine();
predicate.DatabaseSpecificCreator = dqe.Creator;
return predicate.ToQueryText();
}
}
}
and the usage...
var filter = new PredicateExpression(CustomerFields.City == "X");
var sql = new CommonDaoBase().GetQuery(filter);
And for Adapter (for other users), use this:
using SD.LLBLGen.Pro.ORMSupportClasses;
namespace <yourRootNamespace>.DatabaseSpecific
{
public partial class DataAccessAdapter
{
public string GetQuery(PredicateExpression filter)
{
var creator = this.GetDbSpecificCreatorInstance();
filter.DatabaseSpecificCreator = creator;
InsertPersistenceInfoObjects(filter);
return filter.ToQueryText();
}
}
}
... and the usage:
var filter = new PredicateExpression(CustomerFields.Country == "USA");
using (var adapter = new DataAccessAdapter())
{
var sql = adapter.GetQuery(filter);
}