SQL scalar function

37 views
Skip to first unread message

luke8...@gmail.com

unread,
Mar 22, 2014, 5:15:59 AM3/22/14
to blto...@googlegroups.com
Hi,

I am having trouble mapping a SQL Server 2012 scalar function, tried with functions with and without parameters but get exception "No mapping exists from object type <CONTEXT TYPENAME> to a known managed provider native type."

Sample:
create function dbo.MyFunc(@p1 int)
returns uniqueidentifier
as
begin
  return newid()
end

Linq statement calling is something like:
context.MyTable.Where(x => x.Id == context.MyFunc(1)).ToList();


Tried this on my context class:
[SqlFunction("MsSql2012", "dbo.MyFunc({0})", ServerSideOnly = true)]
public Guid MyFunc(int p1)
{
   throw new NotImplementedException("This function is serverside only");
}

or other variant as:
[SqlFunction("MsSql2012", "MyFunc({0})", ServerSideOnly = true)]
[SqlFunction("MsSql2012", "dbo.MyFunc", ServerSideOnly = true)]
[SqlFunction("MsSql2012", "MyFunc", ServerSideOnly = true)]
[SqlFunction("dbo.MyFunc({0})", ServerSideOnly = true)]
[SqlFunction(ServerSideOnly = true)]

Also tried to play with an SqlExpression but nothing helps.

Can anyone help me on this, table valued functions works fine? 

luke8...@gmail.com

unread,
Mar 22, 2014, 7:15:07 AM3/22/14
to blto...@googlegroups.com
Solved!

The method definition needs to be static.

Reply all
Reply to author
Forward
0 new messages