Hello , I am trying to map a function to LLBLgenPro. So far I've settled for a really simple one , just for testing purposes. I am a noob at this so I may be missing something very basic such as using LLBL Gen Pro to generate some code out of SQL functions if there is need for something like that, I couldn't find a function section in the project.
Here is ome of my code
GO
ALTER FUNCTION [dbo].[fn_CalculateDistance](@jobID int)
RETURNS int
AS
BEGIN
DECLARE @toReturn int
set @toReturn = @JobID
RETURN @toReturn
END
public class SQLFunctionMappings : FunctionMappingStore
{
public const string CATALOG_NAME = "xyz";
public const string SCHEMA_NAME = "dbo";
public SQLFunctionMappings(): base()
{
this.Add(new FunctionMapping(typeof(SQLFunctions), "CalculateDistanceBetweeenCoordinates",1 ,"fn_CalculateDistance({0})", SQLFunctionMappings.CATALOG_NAME, SQLFunctionMappings.SCHEMA_NAME));
}
}
public class SQLFunctions
{
public static int CalculateDistanceBetweenCoordinates(int JobID)
{
// empty body, as it's just here to make the query compile. The call is converted to a SQL function.
return 0;
}
}
IDataAccessAdapter adapter = dataTransaction.DataAccessAdapter;
LinqMetaData metaData = new LinqMetaData(adapter);
metaData.CustomFunctionMappings = new SQLFunctionMappings();
var q = from job in metaData.Job
where job.OwningCompanyID == this.CurrentUser.CompanyID
select new { r = SQLFunctions.CalculateDistanceBetweenCoordinates(job.OwningCompanyID) };
foreach (var job in q)
{
System.Diagnostics.Debug.WriteLine(job.r);
};
And it just doesn't work. It always return 0. It looks like it is ignoring the function mapping.
BTW we are using 3.5 framework so i couldn't enable tracing of the DQE through the config because I didn't find the 3.5 visualizers and it gives me a cast exception. I am using the latest runtime libraries though. I also use SQL2005 express.
Can anybody take a quick look at this and maybe tell me what I am missing ? Thank you very much.