Hi,
Thanks for the ideas. I just got round to having a go at this today. so i have added a function to the db as described and i have looked at the docs about how to add a Function to the my code base. However i am having difficulty with the syntax on how to ensure the query.OrderBy(???) can make use of the function.
I have done the following for mapping the function, I'm not 100% sure if it is correct or not:
public class BlahFunctions
{
public static int PurchaseOrderPrioritySort(IEntityField2 field)
{
return 0;
}
/// Class which defines the custom mapping between BlahFunctions.PurchaseOrderPrioritySort and
/// fnPurchaseOrderPrioritySort, the database function.
public class BlahFunctionMappings : FunctionMappingStore
{
public BlahFunctionMappings()
: base()
{
// define the mapping. SQLServer 2000 needs the schema to be present for the function call,
// so we specify that as well.
this.Add(new SD.LLBLGen.Pro.ORMSupportClasses.FunctionMapping(typeof(BlahFunctions), "PurchaseOrderPrioritySort", 1,
"fnPurchaseOrderPrioritySort({0})", "BlahDb", "dbo"));
}
}
}
Then to call the function i get as far as this (Note i have already defined a QuerySpec query by this point):
//set up the custom function mapping store
var mappedFunctions = new BlahFunctions.BlahFunctionMappings();
//assign the custom function mapping store to the query
query.CustomFunctionMappingStore = mappedFunctions;
//at this point i dont see how to actually specify the function in the OrderBy method of the query as it expects a SortClause.
query.OrderBy(BlahFunctions.PurchaseOrderPrioritySort(PurchorderFields.OrdOrderStatus));
Any pointers on how it should be written would be greatly appreciated.
Thanks,
Iain