Can't compile project after importing stored procedure

entity-framework stored-procedures


After importing a stored procedure into my datamodel the project stopped compiling.

It keeps giving me error:

The best overloaded method match for 
(string, params System.Data.Entity.Core.Objects.ObjectParameter[])' 
has some invalid arguments  C:\Users\nikolaev\Documents\MySoft\TicketManager-06 11 2013\TicketManager\TicketDataModel\TicketDataModel\TicketEntities.Context.cs 105 20  TicketDataModel


`Argument 3: cannot convert from 'System.Data.Objects.ObjectParameter' to 
 C:\Users\nikolaev\Documents\MySoft\TicketManager-06 11 2013\TicketManager\TicketDataModel\TicketDataModel\TicketEntities.Context.cs    79  143 TicketDataModel`

The code in context.cs is as follows:

public virtual ObjectResult<sp_get_orphanjobgrades1_Result> sp_get_orphanjobgrades1(Nullable<System.DateTime> start_date, Nullable<System.DateTime> end_date)
            var start_dateParameter = start_date.HasValue ?
                new ObjectParameter("start_date", start_date) :
                new ObjectParameter("start_date", typeof(System.DateTime));

            var end_dateParameter = end_date.HasValue ?
                new ObjectParameter("end_date", end_date) :
                new ObjectParameter("end_date", typeof(System.DateTime));

            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<sp_get_orphanjobgrades1_Result>("sp_get_orphanjobgrades1", start_dateParameter, end_dateParameter);

I read that this may be because of EF 6 and that one needs to download VS 2012 Update 1 and/or EF 6 Tools for VS 2012. I downloaded the tools and I already have update 4 installed, but that doesn't help.

Why is this?

2/14/2014 10:30:35 AM

Accepted Answer

The problem is that your model don't know anything about new parameters. I guess that it happens when your model using EntityFramework (EF) lower version (5.0 for example), but in code you are trying to use EF 6.0.

So, you should either downgrade your code to EF 5.0, or upgrade your model to 6.0.

Upgrading model:

  1. Open Tools -> NuGet Package Manager -> Package Manager Console;
  2. Choose project, that contains your model as Default project on the top of Console.
  3. Type "Uninstall-Package EntityFramework" and press Enter;
  4. After removing, type "Install-Package EntityFramework -version 6.0.0" and press Enter again;
  5. Go to YourModelName.Context.cs and and replace "using System.Data.Objects; using System.Data.Objects.DataClasses;" with "using System.Data.Entity.Core.Objects;". Also, you may need to make the same in all files, where this problem appears.

Or you can downgrade EF version, used in your code. For this, you should do all the same in first 3 steps but in the fourth replace "-version 6.0.0" with "-version 5.0.0". The 5th step is not needed for this.

6/4/2014 8:04:00 AM

Popular Answer

To fix this issue:

If version conflicts, install package for respective version of EF.

If version is same, change the above namespace to System.Data.Entity.Core.Objects

Related Questions


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