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

  • Home
  • SEARCH
  • 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 4327436
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:32:17+00:00 2026-05-21T09:32:17+00:00

I noticed that when Entity Framework generates a method for a stored procedure (function

  • 0

I noticed that when Entity Framework generates a method for a stored procedure (function import), it tests to see if the parameter is null, and makes a decision like this:

if (contactID.HasValue)
{
  contactIDParameter = new ObjectParameter("contactID", contactID);
}  
else
{
  contactIDParameter = new ObjectParameter("contactID", typeof(global::System.Int32));
}

I don’t understand what its trying to do by passing the Type of the parameter as a parameter when the parameter is null? Exactly how does the stored procedure/function get executed in this case?

I did a test myself with SQL Profiler, and noticed that when I intentionally pass null as a parameter (by calling something like context.MyProcedure(null) ), null is simply passed as the parameter to the SQL server’s stored procedure.

Some clarifications on this behavior would be appreciated.

  • 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-21T09:32:18+00:00Added an answer on May 21, 2026 at 9:32 am

    I was interested in this question so I made some investigation.

    ObjectParameter has two overloads – one for passing value and one for passing the type. The second is used if you pass null as the parameter value because EF internally need this. The reason is that function import must be called with ObjectParameters, not with plain parameters you are passing to the wrapping method.

    Internally EF calls:

    private EntityCommand CreateEntityCommandForFunctionImport(string functionName, out EdmFunction functionImport, params ObjectParameter[] parameters)
    {
        ...
        for (int i = 0; i < parameters.Length; i++)
        {
            if (parameters[i] == null)
            {
                throw EntityUtil.InvalidOperation(Strings.ObjectContext_ExecuteFunctionCalledWithNullParameter(i));
            }
        }
        ...
        this.PopulateFunctionEntityCommandParameters(parameters, functionImport, command);
        return command;
    }
    

    As you can see even null value must be represented as ObjectParameter because you can’t simply pass null – it will throw exception. The PopulateFunctionEntityCommandParameters uses information about the type to create correct DbParameter for calling the stored procedure. The value of that parameter is DBNull.Value.

    So you don’t have to deal with it. It is just infrastructure.

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

Sidebar

Related Questions

I am using Entity Framework for the first time and noticed that the entities
I have an entity framework model, and I noticed that one table, a usergroup
I know that Entity Framework supports Partial trust, I personally blogged about that It
I've just noticed that for my entity's id, eclipselink assigns an id 1 +
Everywhere I look, I noticed that both Domain Driven Design (DDD) and entity hydration
I noticed that Google maps is providing directions in my local language (hungarian) when
I noticed that you can call Queue.Synchronize to get a thread-safe queue object, but
I noticed that my Designer.vb file of one of my forms has a lot
We noticed that lots of bugs in our software developed in C# (or Java)
i noticed that paypal displays a very different favicon, one that's not just a

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.