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

问题描述

$ b $ b

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

文件 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?

注意: / strong>警告发生在我之后。

推荐答案

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

In my case, the solution was to modify the T4 template as follows:

ve确定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 andGenerating Artifacts by Using Text Templates, the template can be modified to generate the right code.

以下:


  1. 打开 DataContextEntityObjects.tt / li>
  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.

这篇关于如何摆脱“过时”升级到EF6后的属性警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 07:18
查看更多