WCF RIA 服务中的 DTO 主从

发布于 2024-11-07 09:58:30 字数 1811 浏览 3 评论 0原文

我必须创建一个主从场景,在主控中我可以显示多种类型的项目,它们都实现 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 )。

类层次结构是 ContactPersonCompany 的子类,Person的基类EmployeeCompanyVendor的基类。 Customer 有一个属性 Contact,可以是 ContactPerson,并且有一个 列表>工作

在此处输入图像描述

现在,在主列表中,我想从 DomainService (它是一个 LinqToEntitiesDomainService,我只想选择 IDto 合约中的指定字段,然后在选择时加载详细信息区域中的整个实体及其所有字段/相关数据等

更新:我想到了另一个想法。
创建一个数据库视图 (SQL2008),返回上述 IDto 合约的 3 行,其中枚举将存储为 int 或tinyint(然后将枚举更改为字节),然后在 edm 中可以为列表中存储的每个 EntityType 创建一个按层次结构表,并从 DomainService 返回它。

顺便说一句,所有枚举值都将用于查询,事实上,没有实体会为其 EntityType 属性返回 Contact,因为 Contact 是抽象,可以是 PersonCompany,但我仍然希望有一个选项来查询它们。

更新2
对于列表中的每一项,客户还希望获得其所有作业。
根据我上面描述的层次结构,对于 Customer - 选择其所有作业;对于联系人人员 - 选择其客户工作(如果是客户)。 VendorEmployee 不应该向 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 EntityObjects).

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.

enter image description here

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 Jobs (if its a Customer). Vendor or Employees are not meant to be register with Jobs.

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尸血腥色 2024-11-14 09:58:30

我发现这篇文章非常有用,它实际上让我做出了决定。

  1. 数据库视图不一定是正确的方法
  2. 将通过 POCO DTO 从域服务返回部分实体。

I've found this post very useful, and it actually let me to a desicion.

  1. Database views is not necessarily the right approach
  2. Will return the partial entities thru POCO DTOs from the domain service.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文