How can I permanently fix the "EdmFunctionAttribute Deprecated" warning that appears after upgrading to EF6?

I get a warning “EdmFunctionAttribute deprecated” after I upgraded the first database project from EF4 to EF 6.1.3 :

"System.Data.Entity.Core.Objects.DataClasses.EdmFunctionAttribute" deprecated: "This attribute has been replaced by System.Data.Entity.DbFunctionAttribute." C: \ {myProjectPath} \ DataContextEntityObjects.cs

The attribute is used in various places, such as

[EdmFunction("DataContext", "Split")] public IQueryable<Split_Result> Split(global::System.String rowData, global::System.String splitOn) { // ... auto-generated code ... } 

If you fix this in the * .cs files mentioned in the error message, then every time the model is updated by updating the model from the database , the error appears again.

How can this problem be solved forever (so that updating the model does not cause it again)?

0
c # visual-studio migration entity-framework-4 entity-framework-6
Mar 17 '15 at 8:31
source share
1 answer

The DataContextEntityObjects.cs file is automatically created from DataContextEntityObjects.tt and uses the attribute in various places, such as

  [EdmFunction("DataContext", "Split")] public IQueryable<Split_Result> Split(global::System.String rowData, global::System.String splitOn) { // ... auto-generated code ... } 

Since it is updated automatically every time the model is updated through updating the model from the database , the solution was to change the T4 template as follows:

I have identified the relevant part in the T4 file starting here (lines 214-283):

  //////// //////// Write EntityContainer and ObjectContext Function Import methods. //////// region.Begin(CodeGenerationTools.GetResourceString("Template_RegionFunctionImports")); foreach (EdmFunction edmFunction in container.FunctionImports) { IEnumerable<FunctionImportParameter> parameters = FunctionImportParameter.Create(edmFunction.Parameters, code, ef); 

As indicated in the Practical Guide template . Setting up code generation at the object level and artifact generation using text templates , the template can be changed to create the correct code.

Do the following:

  1. Open the DataContextEntityObjects.tt file
  2. Find and replace the following:

    Edm function replacement

  3. Save the DataContextEntityObjects.tt file

From this moment, every time you update the model, it generates the corresponding * .cs file, correctly creates the attribute inside, and therefore the outdated warning disappears.

+2
Mar 18 '15 at 10:16
source share



All Articles