access a Database scalar value function in Entity framework 6 within linq

c# entity-framework-6 linq sql-server user-defined-functions

Question

What steps i should follow to use the following sql scalar value function within entity framework.

select dbo.GetDefaultAccount(5,1,48)

I tried creating a static class under the same namespace of the edmx and defining the function as following

    [EdmFunction("Model.Store", "GetDefaultAccount")]
    public static int? GetDefaultAccount(int id, Int16 type, int assocId)
    {
        throw new NotSupportedException();
    }

While accessing it from linq like below

  var Accountno = (from s in dbcontext.TranSetups select new { Accountno = CutomEdmxFunctions.GetDefaultAccount(5, 1, 48) })
                       .FirstOrDefault().Accountno;

I get the following error

cannot be translated into a LINQ to Entities store expression because no overload matches the passed arguments

Thanks

1
0
5/13/2015 7:38:29 AM

Popular Answer

Unfortunately, working scalar-valued functions in Entity Framework is not as easy as it supposed to be. After a long googling I found only two methods to work with scalar-valued functions, best described here, but remember: all edits to the .edmx file will be lost when you update the EDM from the database. You will have to re-edit the .edmx file each time. Good luck.

1
7/22/2016 11:29:26 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow