Nestor
Nestor

Reputation: 8384

Entity Framework 6 generates wrong context code

At my workplace, we share a project that uses Entity Framework 6.0 for database operations.

In the repository I see modifications in the MyModel.Context.cs file (a function was added).

From this using block:

using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Linq;

It was changed to this:

using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Core.Objects;
using System.Data.Objects.DataClasses;
using System.Linq;

[EdmFunction("MyEntities", "DbFunction1")]
public virtual IQueryable<DbFunction1_Result> DbFunction1(Nullable<System.Guid> id)
{
   //some code    
   return ((IObjectContextAdapter)this).ObjectContext.CreateQuery<DbFunction1_Result>("[MyEntities].[DbFunction1](@id)", parameter);
}

I updated my working copy and it compiles.

But, whenever I use the Update model from database, my code changes back to this:

using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Linq;

We both use EF 6.0 via NuGet.

When I check the EntityFramework dll's properties, I get this:

enter image description here

What could cause this?

Upvotes: 1

Views: 784

Answers (1)

Tito
Tito

Reputation: 802

Because you need to edit the .tt file. Probably MyModel.Context.tt is the template file that generates the MyModel.Context.cs for you, it uses T4 to generate it each time you select Update model from database in your .edmx file.

Upvotes: 2

Related Questions