在不引用实体框架的情况下公开实体框架 POCO 列表的接口
我正在使用实体框架 4 的 POCO 模板。
我创建了另一个文件来实现上下文对象的部分类。在该文件中,我添加了对我制作的界面的引用。
该界面只有一个属性:
IQueryable<Client> Clients { get; set; }
实际生成的文件中有这个:
public ObjectSet<Patient> Clients
{
get { return _clients ?? (_clients = CreateObjectSet<Client>("Clients")); }
}
private ObjectSet<Client> _clients;
现在, ObjectSet 实现 IQueryable<>。但是当我这样做时,我收到以下错误:
“ClientContracts.ArupEntities”未实现接口成员“RepositoryInterfaces.IClientRepository.Clients”。 “ClientContracts.ArupEntities.Clients”无法实现“RepositoryInterfaces.IClientRepository.Clients”,因为它没有匹配的“System.Linq.IQueryable”返回类型
我认为我可以做到这一点并让它工作。显然我不能...
有没有办法可以将 POCO 实体列表公开为未绑定到实体框架的接口?
I am using the POCO Template for Entity Framework 4.
I made another file to implement the partial class for the context object. In that file I added a reference to an interface that I made.
The interface just has this one property in it:
IQueryable<Client> Clients { get; set; }
The actual generated file has this in it:
public ObjectSet<Patient> Clients
{
get { return _clients ?? (_clients = CreateObjectSet<Client>("Clients")); }
}
private ObjectSet<Client> _clients;
Now, ObjectSet implements IQueryable<>. But when I do this I get the following error:
'ClientContracts.ArupEntities' does not implement interface member 'RepositoryInterfaces.IClientRepository.Clients'. 'ClientContracts.ArupEntities.Clients' cannot implement 'RepositoryInterfaces.IClientRepository.Clients' because it does not have the matching return type of 'System.Linq.IQueryable'
I thought that I could do this and have it work. Clearly I cannot...
Is there a way I can expose the POCO entity lists as an interface that is not bound to the Entity Framework?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,这不是它的工作原理。当您实现接口时,您必须准确返回接口定义中定义的类型。此外,您在示例中使用的通用类型也存在一些差异 -
Patient
/Client
。您可以重新定义接口,例如:
在部分上下文类中使用:
No it is not how it works. When you implement interface you must return exactly the type defined in the interface definition. Also there is some discrepancy in generic types you are using in your example -
Patient
/Client
.You can redefine the interface like:
And in partial context class use: