使用使用 WCF 服务公开的客户端应用程序中的实体框架实体
我有一个 DAL,其中有实体框架来公开实体。这些实体在 WCF 服务项目中使用并公开给客户端。
我通过服务引用在 Silverlight Web 项目中使用这些实体。然后我使用 RIA 域服务进行代码共享。但在尝试加载操作时出现以下错误:
DomainContext context= new DomainContext();
LoadOperation<Genre> lo = context.Load<Genre>(context.GetGenres());
GetGenres() 是一个域服务操作,它加载所有流派。
[Invoke]
public IEnumerable<Genre> GetGenres()
{
return proxy.GetGenres(); //proxy is wcf proxy.
}
该查询返回一个列表。其中 Genre 是 DataContract i 从 WCFServiceReference 获取。
实际错误:
类型“SL.Web.ServiceReference.Genre”不能用作泛型类型或方法中的类型参数“TEntity” 'System.ServiceModel.DomainServices.Client.DomainContext.Load(System.ServiceModel.DomainServices.Client.EntityQuery)'。 没有隐式引用转换 'SL.Web.ChinookServiceReference.Genre' 到 'System.ServiceModel.DomainServices.Client.Entity'。
问题是:
我可以这样做吗?或者我应该在 Silverlight 中有一个自定义类来映射到 WCF 服务数据契约并在 Silverlight 客户端和 Web 项目之间共享自定义实体?
有没有办法使用 DomainService 在 Web 和客户端之间共享服务引用中的实体?
I have a DAL where I have Entity Framework to expose entities. These entities are used in a WCF Service project and exposed to the client.
I consume these entities in the Silverlight web project via service reference. Then I am using a RIA domain service for code sharing. But I get the following error while trying to load operation:
DomainContext context= new DomainContext();
LoadOperation<Genre> lo = context.Load<Genre>(context.GetGenres());
GetGenres() is a Domain Service operation where it loads all Genres.
[Invoke]
public IEnumerable<Genre> GetGenres()
{
return proxy.GetGenres(); //proxy is wcf proxy.
}
This Query returns a List. Where Genre is the DataContract i
got from the WCFServiceReference.
Actual Error:
The type 'SL.Web.ServiceReference.Genre' cannot be used as type parameter 'TEntity' in the generic type or method
'System.ServiceModel.DomainServices.Client.DomainContext.Load(System.ServiceModel.DomainServices.Client.EntityQuery)'.
There is no implicit reference conversion from
'SL.Web.ChinookServiceReference.Genre' to
'System.ServiceModel.DomainServices.Client.Entity'.
Question is:
Can I do this way or should I have a custom class in Silverlight that maps to the WCF service datacontract and share the custom entity between the Silverlight client and Web project?
Is there a way to share entities from a service reference between Web and client using a DomainService??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题在于您已将 GetGenres 标记为调用操作。如果你将其标记为查询操作并重建,我认为你会处于良好状态。
The problem is that you have GetGenres marked as an Invoke operation. If you mark it as a query operation and rebuild, I think that you will be in good shape.