1

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?

1

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

But the T4 file is generated from the database based on the EF version I use, doesn't it?
The .cs is generated from the .tt file, the .tt only uses the parameters you change on the .edmx file. Try to copy and paste your code on this .tt file in the correct place and try to Update model from database, later check if it was generated on the Model.Context.cs.
Depends also on the version of the Visual Studio you use, please check this link msdn.microsoft.com/en-us/data/jj613116.aspx on DbContext Generator.
It seems that the project has mixed EF referencies. It seemingly uses EF 6 but also contained a System.Data.Entity reference and the *.tt files were also EF5 compatible, so I delete them, and added a new code generation item as described in the MS guide. Now it gets compiled.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.