如何永久修复"EdmFunctionAttribute已过时"?警告,升级到EF6后会发生什么? [英] How can I permanently fix the "EdmFunctionAttribute is obsolete" warning, which occurs after upgrading to EF6?

查看:177
本文介绍了如何永久修复"EdmFunctionAttribute已过时"?警告,升级到EF6后会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我先先升级数据库后,收到警告"EdmFunctionAttribute已过时" 项目从EF4升级到EF 6.1.3 :

"System.Data.Entity.Core.Objects.DataClasses.EdmFunctionAttribute"为 已过时:此属性已替换为 System.Data.Entity.DbFunctionAttribute". C:\ {myProjectPath} \ DataContextEntityObjects.cs

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

该属性用于类似

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

如果您在错误消息提到的* .cs文件中进行了修复,那么每次通过从数据库更新模型来更新模型时, 错误再次出现.

If you fix that in the *.cs-files mentioned by the error message, then each time when the model gets updated via update the model from database, the error comes up again.

如何永久解决此问题(因此模型更新不会再次出现)?

How can this issue permanently be fixed (so a model update doesn't bring it up again)?

推荐答案

文件DataContextEntityObjects.cs是根据DataContextEntityObjects.tt自动生成的,并在诸如

The file DataContextEntityObjects.cs is auto-generated from DataContextEntityObjects.tt and uses the attribute in various places like

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

由于每次通过从数据库更新模型进行模型更新时,模型都是自动重新生成, 解决方案是修改T4模板,如下所示:

Since it is auto-regenerated each time when the model gets updated via update the model from database, the solution was to modify the T4 template as follows:

我已经确定T4文件中的相关部分从此处开始(第214-283行):

I've identified the relevant part in the T4 file starts 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 suggested in the template How to: Customize Object Layer Code Generation and Generating Artifacts by Using Text Templates, the template can be modified to generate the right code.

执行以下操作:

  1. 打开DataContextEntityObjects.tt文件
  2. 搜索并替换以下内容:

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

保存文件DataContextEntityObjects.tt

从现在开始,每次更新模型时,都会生成相应的* .cs文件,在内部正确创建属性,因此过时的警告消失了.

From now on, each time you update the model, this will generate the corresponding *.cs file, create the attribute inside correctly and hence the obsolete warning goes away.

这篇关于如何永久修复"EdmFunctionAttribute已过时"?警告,升级到EF6后会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆