Function Mapping (linq)

Posts   
 
    
niemimik
User
Posts: 32
Joined: 27-Apr-2004
# Posted on: 19-Dec-2012 13:25:53   

Hi!

I'm trying to make functionmapping work with my linqmetadata. But i cannot see any mapping actually done. (I can trace call to static implementations) Function only return value from static implementation.

SQL Trace does any call to function either...

Also tried with unittesting without retreiving any result from DB.

I created function from online manual and placed it to database with small modifications (returns only static value).

Using LLBLGen v2.6 or v3.5 makes no difference.

I think I'm totally missing some basic stuff here...

LinqPad 4, SQL Server 2008, VS2012

BR,

-mikko

CREATE  FUNCTION fn_CalculateOrderTotal(@orderID int, @useDiscounts bit)
RETURNS DECIMAL
AS
BEGIN
    DECLARE @toReturn DECIMAL

    set @toReturn = 1500.25

    RETURN @toReturn
END

Linq (linqpad)

this.CustomFunctionMappings = new CustFunctionsMappings();

var query = from v in SopimusVaraus
      select new 
   { 
        v.ID,
        CalValue=  CustFunctions.CalculateOrderTotal(10050,true)
    };
    
this.CustomFunctionMappings = null;

Mapping

public class CustFunctions
    {
        
        public static decimal CalculateOrderTotal(int orderId, bool useDiscounts)
        {
            // empty body, as it's just here to make the query compile. The call is converted to a SQL function.
            return 0.0M;
        }

    }


    public class CustFunctionsMappings : FunctionMappingStore
    {
        public CustFunctionsMappings()
            : base()
        {

            this.Add(new FunctionMapping(typeof(CustFunctions), "CalculateOrderTotal", 2,
                        "fn_CalculateOrderTotal({0}, {1})", "testdb", "dbo"));
        }
    }
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 19-Dec-2012 21:18:44   

in Linqpad try to set the CustomFunctionMappings of the LinqMetaData, or the CustomFunctionMappingStore of the "query" (IQueryable object).