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 7954677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:30:07+00:00 2026-06-04T03:30:07+00:00

I have a SP in my database. For EF4.1, using the DbContext API .

  • 0

I have a SP in my database. For EF4.1, using the DbContext API.

After importing the function from the data model, references to the stored procedure works fine in my development environment. But when published to the server, it fails with a message like: The FunctionImport ‘SqlSearch’ could not be found in the container ‘TallyJ2Entities’. All other data access is working fine.

It seems that in production, some aspects of the EF4 configuration are forgotten.

The databases are identical, and both servers are SQL 2008 (local is Express SP1 10.50.2500, host is Express RTM 10.50.1600).

I’ve even pointed the EDMX editor directly to the production database, and updated. The result worked fine in development, but fails in the same way on the server.

Other similar questions here don’t help. Someone else seems to have a similar problem enter link description here.

Any suggestions?

Update: I’ve found that the problem goes away when I deploy the host in Debug mode!

Inside my DbContext derived class, I put this code:

((IObjectContextAdapter)this).ObjectContext.MetadataWorkspace
var findFunction = metadataWorkspace.GetItems(DataSpace.SSpace)
            .SelectMany(gi => gi.MetadataProperties)
            .Where(m=> Equals(m.Value, "SqlSearch"))
            .Select(m => "Found {0}".FilledWith(m.Value))
            .FirstOrDefault();

When I logged the findFunction result, it turns out that the server (in Release mode) did NOT find it, while in development, it is found.

  • 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-06-04T03:30:09+00:00Added an answer on June 4, 2026 at 3:30 am

    If using EF 4.1 and above, change “ObjectParameter” to “SqlParameter” and “ExecuteFunction” to “ExecuteStoreQuery” in your Context.cs file.

    The “ExecuteStoreQuery” method also expects you to add the parameter names in-front of the stored proc. Find a snippet below:

    var param1Parameter = param1 != null ?
    new SqlParameter("param1", param1) :
    new SqlParameter("param1", typeof(string));
    
    var param2Parameter = param2 != null ?
    new SqlParameter("param2", param2) :
    new SqlParameter("param2", typeof(int));
    
    return ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreQuery<sp_TestSproc_Result>("sp_TestSproc @param1, @param2", param1Parameter, param2Parameter);
    

    If using a template to generate your code, you might find the snippet below useful also. I.e. I’ve modified the standard “Fluent TT” generator to suit EF 4.3:

        void WriteFunctionImport(EdmFunction edmFunction, bool includeMergeOption)
        {
            var parameters = FunctionImportParameter.Create(edmFunction.Parameters, Code, EFTools);
            var paramList = String.Join(", ", parameters.Select(p => p.FunctionParameterType + " " + p.FunctionParameterName).ToArray());
            var returnType = edmFunction.ReturnParameter == null ? null : EFTools.GetElementType(edmFunction.ReturnParameter.TypeUsage);
            var processedReturn = returnType == null ? "int" : "ObjectResult<" + MultiSchemaEscape(returnType) + ">";
    
            if (includeMergeOption)
            {
                paramList = Code.StringAfter(paramList, ", ") + "MergeOption mergeOption";
            }
        #>
    
            <#=AccessibilityAndVirtual(Accessibility.ForMethod(edmFunction))#> <#=processedReturn#> <#=Code.Escape(edmFunction)#>(<#=paramList#>)
            {
        <#+
                if(returnType != null && (returnType.EdmType.BuiltInTypeKind == BuiltInTypeKind.EntityType ||
                                          returnType.EdmType.BuiltInTypeKind == BuiltInTypeKind.ComplexType))
                {
        #>
                ((IObjectContextAdapter)this).ObjectContext.MetadataWorkspace.LoadFromAssembly(typeof(<#=MultiSchemaEscape(returnType)#>).Assembly);
    
        <#+
                }
    
                foreach (var parameter in parameters.Where(p => p.NeedsLocalVariable))
                {
                    var isNotNull = parameter.IsNullableOfT ? parameter.FunctionParameterName + ".HasValue" : parameter.FunctionParameterName + " != null";
                    var notNullInit = "new SqlParameter(\"" + parameter.EsqlParameterName + "\", " + parameter.FunctionParameterName + ")";
                    var nullInit = "new SqlParameter(\"" + parameter.EsqlParameterName + "\", typeof(" + parameter.RawClrTypeName + "))";
        #>
                var <#=parameter.LocalVariableName#> = <#=isNotNull#> ?
                    <#=notNullInit#> :
                    <#=nullInit#>;
    
        <#+
                }
    
                var genericArg = returnType == null ? "" : "<" + MultiSchemaEscape(returnType) + ">";
                var callParams = Code.StringBefore(", ", String.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray()));
                var spParams = Code.StringBefore("@", String.Join(", @", parameters.Select(p => p.EsqlParameterName).ToArray()));
    
                if (includeMergeOption)
                {
                    callParams = ", mergeOption" + callParams;
                }
        #>
                return ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreQuery<#=genericArg#>("<#=edmFunction.Name#> <#=spParams#>"
                            <#=callParams#>);
            }
        <#+
            if(!includeMergeOption && returnType != null && returnType.EdmType.BuiltInTypeKind == BuiltInTypeKind.EntityType)
            {
                WriteFunctionImport(edmFunction, true);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database which is created using EF4.1 code first. The data context
I am using EF4 in my application. In database, I have computed column which
I am using EF4.1, have upgraded my project, generated POCO classes to use DbContext
I have an entity model build using EF4.1 code first, which uses a WCF
I'm learning EF4.1 against the northwind database. I have created a POCO class like
I have a real entity Division under database model (EF 4.0). Also I have
i have DataBase function that calculate distance by coordinates CREATE OR REPLACE FUNCTION distance(lat1
NOTE: I'm using EF 4.2 with Database First Method and DbContext. This is NOT
I have a exceedingly simplistic data model (below). I am having trouble figuring out
I have an EF4.1 database first application, and the .ToString() method is only giving

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.