Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't compile project after importing stored procedure

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

It keeps giving me error:

The best overloaded method match for 
'System.Data.Entity.Core.Objects.ObjectContext.ExecuteFunction<TicketDataModel.sp_get_orphanjobgrades1_Result>
(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

and

`Argument 3: cannot convert from 'System.Data.Objects.ObjectParameter' to 
'System.Data.Entity.Core.Objects.ObjectParameter'   
 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?

like image 642
AunAun Avatar asked Feb 14 '14 10:02

AunAun


1 Answers

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 YourModelName.Context.tt 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.

like image 150
Alex Yagur Avatar answered Sep 19 '22 18:09

Alex Yagur