Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6242875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:02:09+00:00 2026-05-24T12:02:09+00:00

I have a Scalar-valued function in my DB: ALTER FUNCTION [dbo].[fx_fooFunct] (@MyParam varchar(max)) RETURNS

  • 0

I have a Scalar-valued function in my DB:

ALTER FUNCTION [dbo].[fx_fooFunct]
  (@MyParam varchar(max))
RETURNS varchar(max)
AS
BEGIN
  return @MyParam
END

I want to call this function from a LINQ to Entities query and get the result into a variable:

let result = this.ObjectContext.ExecuteFunction<string>("SELECT dbo.fx_fooFunct(@MyParam)", new ObjectParameter("MyParam", "hello world")).FirstOrDefault()

But, when I execute the code, I get this error:

LINQ to Entities does not recognize the method
‘System.Data.Objects.ObjectResult`1[System.String]
ExecuteFunction[String](System.String,
System.Data.Objects.ObjectParameter[])’ method, and this method cannot
be translated into a store expression.

Other Info:

This is part all of a query running on the server.
Returning all the data and using LINQ to Objects is not an option due to performance.

I’m not sure that I have the return type of the ExecuteFunction correct, but I’m not sure what else it could be…
What am I doing wrong?

Edit
With the help of Ladislav Mrnka’s answer, here is the solution:

Create helper method exposing the SQL function:

public class CustomSqlFunctions
{
    [EdmFunction("MyModel.Store", "fx_fooFunct")]
    public static string FooFunct(string myParam)
    {
        throw new NotSupportedException("Direct calls not supported");
    }
} 

The LINQ should now read:

let result = CustomSqlFunctions.FooFunct("hello world")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:02:11+00:00Added an answer on May 24, 2026 at 12:02 pm

    Do you have your function mapped in EDMX? I guess you don’t.

    Run Update from database wizard in the designer and under stored procedures select your SQL function to import and follow this article to create helper method marked with EdmFunctionAttribute to expose the SQL function for LINQ-TO-Entities.

    Note: SQL functions are not supported in code-first / fluent-API. You need to use mapping with EDMX.

    ExecuteFunction is used to call features mapped in EDMX – it expects name of the mapped feature (function imports of stored procedures). MSDN says that it can also call mapped functions but I don’t know how – it calls function import and SQL function import doesn’t have any.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

say I have a scalar-valued function with takes two Guids as parameters: dbo.CarDistribution The
Regarding to SQL performance. I have a scalar valued function for checking some specific
We have a scalar function that returns a DateTime. It performs a couple of
Is there any way to execute a scalar-valued function from within a Derived Column
I have a view (actually, it's a table valued function, but the observed behavior
I have a user defined function in a SQL Server 2005 database which returns
I have a recursive scalar function that needs to update a record in another
I am using a Scalar-Valued Function to find out if a user of the
We have scalar functions in our database for returning things like number of tasks
I have an implicit scalar field defined in 2D, for every point in 2D

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.