WCF RIA 服务中的 DTO 主从
我必须创建一个主从场景,在主控中我可以显示多种类型的项目,它们都实现 IDto
:
interface IDto
{
int Id { get; set; }
string Title { get; set; }
EntityType { get; set;
}
enum EntityType
{
Contact,
Person,
Company,
Customer
Employee,
Vendor,
Job
}
注意:我正在使用实体框架 EDM(生成的 ObjectContext 和
EntityObject
)。
类层次结构是 Contact
是 Person
和 Company
的子类,Person
是 的基类Employee
、Company
是Vendor
的基类。 Customer
有一个属性 Contact
,可以是 Contact
或 Person
,并且有一个 列表>工作
。
现在,在主列表中,我想从 DomainService (它是一个
LinqToEntitiesDomainService
,我只想选择 IDto
合约中的指定字段,然后在选择时加载详细信息区域中的整个实体及其所有字段/相关数据等
更新:我想到了另一个想法。
创建一个数据库视图 (SQL2008),返回上述 IDto 合约的 3 行,其中枚举将存储为 int 或tinyint(然后将枚举更改为字节),然后在 edm 中可以为列表中存储的每个 EntityType 创建一个按层次结构表,并从 DomainService
返回它。
顺便说一句,所有枚举值都将用于查询,事实上,没有实体会为其 EntityType
属性返回 Contact
,因为 Contact
是抽象,可以是 Person
或 Company
,但我仍然希望有一个选项来查询它们。
更新2
对于列表中的每一项,客户还希望获得其所有作业。
根据我上面描述的层次结构,对于 Customer
- 选择其所有作业;对于联系人
或人员
- 选择其客户
的工作
(如果是客户)。
Vendor
或 Employee
不应该向 Job
注册。
我认为我能做到这一点的唯一方法是使用数据库视图。
我错了吗?后果是什么?我正在使用 SL5 和 RIA。
景色好吗?或者我应该使用客户端 POCO 处理客户端中的所有查询?因为实际上该值仅用于检索联系人姓名及其职位。进一步的细节和操作将在 Entity
实体本身的其他视图中完成。
那么各位专家怎么看呢?
I have to make a Master-Detail scenario where in the master I can show many types of items, that they all implement IDto
:
interface IDto
{
int Id { get; set; }
string Title { get; set; }
EntityType { get; set;
}
enum EntityType
{
Contact,
Person,
Company,
Customer
Employee,
Vendor,
Job
}
Note: I am using Entity Framework EDM (generated ObjectContext
and EntityObject
s).
The class hierarchy is that Contact
is the subclass for Person
and Company
, Person
is the baseclass of Employee
, Company
is the baseclass of Vendor
. Customer
has a property Contact
that can be either a Contact
or a Person
, and has a list of Job
.
Now in the master list, I want to load a collection of DTOs from the DomainService
(it's a LinqToEntitiesDomainService<ObjectContext>
, and I want only the specified fields in the IDto
contract to be selected, then, when selected, load the entire entity with all its fields/related data etc. in the details area.
Update: I thought about another idea.
Create a database-view (SQL2008) that returns the 3 rows of the above IDto
contract where the enum will be stored as int or tinyint (will then change the enum to byte), then in the edm I can make a table-per-hierarchy for each EntityType stored in the list, and return it from the DomainService
.
BTW, all the enum values will be used for the query, in fact, no entity will return Contact
for its EntityType
property, because Contact
is abstract and can be either a Person
or a Company
, but I still want to have an option to query both of them.
Update 2
The customer also wants, for each one of the items in the list, also all its jobs.
Based on the hierarchy I described above, for a Customer
- select all its jobs; for a Contact
or a Person
- select its Customer
's Job
s (if its a Customer
). Vendor
or Employee
s are not meant to be register with Job
s.
I think the only way I can do this is with database-views.
Am I wrong? What are the consequences? I am using SL5 with RIA.
Is the Views way good? Or I should handle all the queries in the client using a client POCO? because really this value are only used to retrieve the contact name and its jobs. further details and manipulation will be done in other views on the Entity
entities them selves.
So what do you experts think?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现这篇文章非常有用,它实际上让我做出了决定。
I've found this post very useful, and it actually let me to a desicion.