问题描述
我收到警告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
文件 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?
注意:发生警告之后我有。
推荐答案
在我的情况下,解决的办法是修改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 andGenerating Artifacts by Using Text Templates, the template can be modified to generate the right code.
执行下列操作
- 打开了
DataContextEntityObjects.tt
文件
-
搜索和替换以下内容:
- Open up the
DataContextEntityObjects.tt
file Search and replace the following:
这将产生相应的* cs文件,替换属性和过时的警告消失。
This will generate the corresponding *.cs file, replace the attribute and the obsolete warning goes away.
这篇关于无法摆脱的"过时的"升级到EF6后属性警告。如何解决这一问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!