无法摆脱的"过时的"升级到EF6后属性警告。如何解决这一问题? [英] Cannot get rid of "Obsolete" attribute warning after upgrading to EF6. How to fix this?

查看:507
本文介绍了无法摆脱的"过时的"升级到EF6后属性警告。如何解决这一问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到警告EdmFunctionAttribute已经过时了后,我已经升级了数据库的第一个项目从EF4来到EF 6.1.3:

I am getting the warning "EdmFunctionAttribute is obsolete" after I have upgraded a database first project from EF4 to EF 6.1.3:

System.Data.Entity.Core.Objects.DataClasses.EdmFunctionAttribute'是
过时:这个属性已经换成
系统。 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

文件 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 ...
    }

既然是自动再生我的更新从数据库模型 ?,我怎样才能摆脱这种警告的永久

Since it is auto-regenerated when I update the model from database, how can I get rid of this warning permanently?

注意:发生警告之后我有评级从EF4 EDMX一个项目,EF6

推荐答案

在我的情况下,解决的办法是修改T4模板如下:

In my case, 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:

这将产生相应的* cs文件,替换属性和过时的警告消失。

This will generate the corresponding *.cs file, replace the attribute and the obsolete warning goes away.

这篇关于无法摆脱的&QUOT;过时的&QUOT;升级到EF6后属性警告。如何解决这一问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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