如何将多个 WCF RIA 实体类型转换为单个类型以在 ViewModel 中使用
如果有太多/不够详细或其中一些不相关的内容,请深表歉意,这是我在此论坛上发表的第一篇文章:
背景
我目前正在使用 C# 开发基于 Silverlight 4 和 WCF RIA (SP1) 的应用程序VS2010。堆栈是:SQL Server -> nHibernate->域服务->服务代理-> Silverlight 4 客户端 (MVVM)
我在数据库中有 4 个表,其中具有相同的字段,每个表保存相同数据的不同“类型”。
数据实际上应该位于一个带有类型列的表中,但它是一个我无法更改的旧数据库。
我为每个表创建了一个 POCO 和一个处理访问和更新四个不同实体集的域服务。这些类型被投射到 Silverlight 客户端,并且所有 CRUD 内容都按预期工作。
问题
我有一个视图模型,其中包含一个 ObservableCollection,其中 T 是 4 个实体类型之一,但是我不想使用 4 个集合来保存不同的实体类型。 UI 将允许用户选择类型,我想使用相同的集合和 UI 绑定来编辑该数据。
我已尝试
创建通用域服务,但不支持它们。
让服务器端实体类型继承抽象类或实现接口,但域服务不投影抽象类或接口。
为实现客户端接口的 4 个投影实体创建客户端部分类。但是,当我尝试将
ObservableCollection
分配给ObservableCollection
时,出现以下错误:
无法隐式转换类型“System.Collections.ObjectModel”。 ObservableCollection
我怀疑原因是 StandardInterestRate 继承自 RIA Entity 类。任何想法表示赞赏。
Apologies if there's too much/not enough detail or some of it is irelevant, it's my first post on this board:
Background
I am currently developing a Silverlight 4 and WCF RIA (SP1) based application in C# using VS2010. The stack is: SQL Server -> nHibernate -> Domain Service -> Service Agent -> Silverlight 4 Client (MVVM)
I have 4 tables in the database with the same fields in them each table holding a different 'type' of the same data.
The data should really be in one table with a type column but its a legacy database that I can't change.
I have created a POCO per table and a single domain service that handles accessing and updating the four different entity sets. These types are projected to the Silverlight Client and all the CRUD stuff works as expected.
Problem
I have a viewmodel that in which contains an ObservableCollection where T is one of the 4 entity types, however I don't want to use 4 collections to hold the different entity types. The UI will allow the user to select a type and I want to use the same collection and UI bindings to edit that data.
I have tried
Creating a generic domain service, but they are not supported.
Having the server side entity types inherit from an abstract class or implement an interface but domain services don't project abstract classes or interfaces.
Creating client side partial classes for the 4 projected entities that implement a client side interface. However when I try and assign the
ObservableCollection<MyEntity>
toObservableCollection<MyEntityInterface>
I Get the following error:
Cannot implicitly convert type 'System.Collections.ObjectModel.ObservableCollection<BusinessDomain.StandardInterestRate>' to 'System.Collections.ObjectModel.ObservableCollection<BusinessDomain.IInterestRate>'
I suspect the reason is that StandardInterestRate inherits from the RIA Entity class. Any thoughts appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
Try