I have two issues, I think both are related:
First issue:
Given a TSQL UDF that returns a BIT and doing a standard function mapping to a function like:
public static int SomeTestFunction(int someId)
{
return 0;
}
Then calling that function in linq works, it returns a 1 or 0. However, the rest of LLBLGen maps bit to boolean so I tried:
public static bool SomeTestFunction(int someId)
{
return false;
}
It crashes.
The reason is when it is an INT the DQE emits a query like
[db].[dbo].SomeTestFunction(bla)
When it is a boolean mapped function, the DQE emits a query like
CASE WHEN [db].[dbo].SomeTestFunction(bla) THEN 1 ELSE 0 END
So, when doing function mappings, is there a way we can make this work, or do I have to keep returning INT values and then comparing them to 1 or 0? This has actually a pain point for me for a while; I just worked around it; but finally decided I should report it to see if it could be fixed
Crash data (doubt you need)
An exception was caught during the execution of a retrieval query: An expression of non-boolean type specified in a context where a condition is expected, near 'THEN'.
Incorrect syntax near 'LPLA_1'.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.
at SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.Execute(CommandBehavior behavior)
at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetAsDataReader(ITransaction transactionToUse, IRetrievalQuery queryToExecute, CommandBehavior readerBehavior)
at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetAsProjection(List1 valueProjectors, IGeneralDataProjector projector, ITransaction transactionToUse, IRetrievalQuery queryToExecute, Dictionary
2 typeConvertersToRun)
at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetAsProjection(List1 valueProjectors, IGeneralDataProjector projector, ITransaction transactionToUse, QueryParameters parameters)
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider.ExecuteValueListProjection(QueryExpression toExecute)
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.ExecuteExpression(Expression handledExpression)
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.Execute(Expression expression)
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable
1 source)
Second issue:
Given the same TSQL UDF that returns a BIT and doing a standard function mapping to a function like:
public static int SomeTestFunction(int someId)
{
return 0;
}
I then execute the following linq:
var data = (from table in metaData.Table
where table.pKey=12
select MyCustomFunctionMapping.SomeTestFunction(table.pKey)).FirstOrDefault()
That works just fine...the issue is sometimes when writing the above since I know I am getting one row and table.pKey will equal 12, I may write...
var data = (from table in metaData.Table
where table.pKey=12
select MyCustomFunctionMapping.SomeTestFunction(12)).FirstOrDefault()
This will not map to the TSQL function at all and simply returns the result of the extension defined above (a zero). In the case of extensions that are function mappings it should always result in TSQL code calling it, even if the only values being passed are constants!
(of course I do not even need that table or anything, but hey, we have already hashed this out and it is on the 'feature' list: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=22702 )
So, at the end of the day for both scenarios, the DQE needs to do different things based on a regular extension being called vs a linq function mapping extension being called.
Thoughts?
4.1.14.225 OrmSupport
4.1.14.110 DQE Sql Server