Ok, that makes me feel better.
Now back to the original question post, is there a way to call the functions without involving a table that is unused anyway?
Given this:
select OrderId, dbo.CalculateOrderTotal(OrderId, true) from Orders where CustomerID="CHOPS"
If I already knew the OrderId, I would really only need to execute this:
select dbo.CalculateOrderTotal(@p1, true)
Hate having to write this:
metaData.CustomFunctionMappings = new NorthwindFunctionMappings();
// fetch the orders with the total calculated by the function inside the database
var q = (from o in metaData.Order
where o.OrderId == 100
select new { OrderTotal = NorthwindFunctions.CalculateOrderTotal(100, true) ).ToCacheResultset(300);
Which would generate:
select dbo.CalculateOrderTotal(100, true) from Orders where OrderId=100
which of course has a useless where clause, causes an index seek on SQL, etc.
Wondering if there was some linq syntax or extension that we could use that would let it know to not use the table...
metaData.CustomFunctionMappings = new NorthwindFunctionMappings();
// fetch the orders with the total calculated by the function inside the database
var q = (from o in metaData.Order
where o.OrderId == 100
select new { OrderTotal = NorthwindFunctions.CalculateOrderTotal(100, true) ).FunctionCallOnly().ToCacheResultset(300);
If I could do the above (or something similar), I would not have to write all the code around DBFunctionCall.GetScalar() and could use Linq and caching and such...