不能在通用类型或方法中用作类型参数“TElement” [英] Cannot be used as type parameter 'TElement' in the generic type or method
问题描述
我已经从 POCO 生成实体类,但它在ObjectSet和CreateObjectSet上有问题,我通过用ObjectQuery和CreateQuery替换它们来修复。
但是我仍然在 EntityGenerator.Context.cs $ c中的以下代码中有一个问题$ c>,
代码是
public ObjectResult< lead> ; GetLeads()
{
** return base.ExecuteFunction< lead>(GetLeads); **
}
错误是
Proj.EntityModel.employee不能用作类型参数'TElement'
在通用类型或方法
'System.Data.Objects.ObjectContext.ExecuteFunction(string,
params System.Data.Objects.ObjectParameter [])'。没有从'Proj.EntityModel.employee'到
'System.Data.Objects.DataClasses.IEntityWithChangeTracker'的隐式
引用转换。
这是什么错误?什么是解决方案?
听起来你只需要使 employee
实现 IEntityWithChangeTracker
。
(我怀疑你已经剪切并粘贴错误的代码段,关于 employee
的错误说明,您的代码谈论 lead
,我也鼓励您更改名称,以便他们遵循.NET命名约定。)
I am using Entity Model, C#, .NET Framework 3.5. I have generated entity classes from POCO, but it had issues on ObjectSet and CreateObjectSet which I fixed by replacing them with ObjectQuery and CreateQuery.
But I still have one issue in following code in EntityGenerator.Context.cs
,
The code is
public ObjectResult<lead> GetLeads()
{
**return base.ExecuteFunction<lead>("GetLeads");**
}
And the error is
Proj.EntityModel.employee cannot be used as type parameter 'TElement' in the generic type or method 'System.Data.Objects.ObjectContext.ExecuteFunction(string, params System.Data.Objects.ObjectParameter[])'. There is no implicit reference conversion from 'Proj.EntityModel.employee' to 'System.Data.Objects.DataClasses.IEntityWithChangeTracker'.
What's this error? What's solution?
It sounds like you just need to make employee
implement IEntityWithChangeTracker
.
(I suspect you've cut and paste the wrong section of code though, given that the error talks about employee
and your code talks about lead
. I'd also encourage you to change your names so that they follow .NET naming conventions.)
这篇关于不能在通用类型或方法中用作类型参数“TElement”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!