简体   繁体   English

不能在泛型类型或方法中用作类型参数“TElement”

[英]Cannot be used as type parameter 'TElement' in the generic type or method

I am using Entity Model, C#, .NET Framework 3.5.我正在使用实体 Model、C#、.NET 框架 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.我已经从POCO生成了实体类,但它在 ObjectSet 和 CreateObjectSet 上有问题,我通过用 ObjectQuery 和 CreateQuery 替换它们来修复它们。

But I still have one issue in following code in EntityGenerator.Context.cs ,但是我在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[])'. Proj.EntityModel.employee 不能用作泛型类型或方法“System.Data.Objects.ObjectContext.ExecuteFunction(string, params System.Data.Objects.ObjectParameter[])”中的类型参数“TElement”。 There is no implicit reference conversion from 'Proj.EntityModel.employee' to 'System.Data.Objects.DataClasses.IEntityWithChangeTracker'.没有从“Proj.EntityModel.employee”到“System.Data.Objects.DataClasses.IEntityWithChangeTracker”的隐式引用转换。

What's this error?这是什么错误? What's solution?有什么解决办法?

It sounds like you just need to make employee implement IEntityWithChangeTracker .听起来您只需要让employee实现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.) (我怀疑您剪切并粘贴了错误的代码部分,因为错误涉及employee ,而您的代码涉及lead 。我还鼓励您更改名称,以便它们遵循 .NET 命名约定。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通用方法-类型不能用作类型参数 - Generic method - Type cannot be used as Type Parameter 类型“ XXX”不能用作通用类型或方法中的类型参数“ T” - The type 'XXX' cannot be used as type parameter 'T' in the generic type or method 该类型不能用作泛型类型或方法UserStore中的类型参数TRole - The type cannot be used as type parameter TRole in the generic type or method UserStore 类型“ T”不能用作通用类型或方法中的类型参数“ T” - The type 'T' cannot be used as type parameter 'T' in the generic type or method 该类型不能用作通用类型或方法中的类型参数 - The type cannot be used as type parameter in the generic type or method 类型&#39;&#39;不能在通用类型或方法中用作类型参数&#39;T&#39; - The type '' cannot be used as type parameter 'T' in the generic type or method 存储库不能用作方法的通用类型中的类型参数 - Repository cannot be used as a type parameter in the generic type of method 当类型已知时,类型&#39;T&#39;不能用作泛型类型或方法错误中的类型参数 - The type 'T' cannot be used as type parameter in the generic type or method error when type is known 错误:“该类型不能用作方法的通用类型中的类型参数。”这可以通过约束或强制转换来解决吗? - Error: “The type cannot be used as type parameter in the generic type of method.” Can this be solved with constraints or casting? 类型“Pulse.Data.Entity.WHUserClaim”不能用作泛型类型或方法中的类型参数“TUserClaim” - The type 'Pulse.Data.Entity.WHUserClaim' cannot be used as type parameter 'TUserClaim' in the generic type or method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM