DTO 和 WCF RIA
我有一个 DTO,其中包含另一个 DTO 的集合,我将其填充到服务器端并将其发送到客户端。但是,此内部 DTO 集合不会返回给客户端。
我相信我需要使用 [Include] 和 [Association] 属性,以便 WCF RIA 服务知道要做什么,但是我的问题是主 DTO 和内部 DTO 集合之间没有真正的关联,我是只是用它来聚合来自各种来源的数据以返回给客户端。
我对我想要实现的目标的理解是否错误,如果不是,我如何让 WCF RIA 发送此内部 DTO 集合。
我应该补充一点,我正在使用自动映射器并希望使用它来实现它。
这是一个例子,我想以一大块的形式发送回客户端;
- 员工拥有的能力。
- 员工工作所需的能力。
- GAP,即 1 和 2 之间的差异。
公共类 CompetencyRequirementsDto { [钥匙] 公共字符串 CompanyId { 获取;放; } [钥匙] 公共字符串员工编号{获取;放; } 公共字符串 JobId { 获取;放; } [包括] [关联(“员工能力”,“公司 ID,员工编号”,“公司 ID,员工编号”)] 公共 IList
员工能力{获取;放; } [包括] [协会(“工作能力”,“工作ID,公司ID”,“工作ID,公司ID”)] 公共 IList 工作能力{获取;放; } [包括] [关联(“能力差距”,“JobId,CompanyId”,“JobId,CompanyId”)] 公共 IList 能力差距{获取;放; } } }
现在第 1 项工作正常,但第 2 项和第 3 项却不行?我发现我的 DTO 在服务器端创建正常,但是当它到达客户端时 CompetencyGap(即使它没有值)有 已被赋予工作能力值。
I have a DTO which has a collection within it of another DTO which I populate server-side and send to the client. However, this inner DTO collection is not returned to the client.
I believe I need to use the [Include] and [Association] attributes so that WCF RIA services knows what to do, however my issue with this is there is no real association as such between the main DTO and the inner DTO collection, I am just using it to aggregate data from various sources for return to the client.
Is my understanding wrong in what I am trying to achieve, if not how do I get WCF RIA to send this inner DTO collection.
I should add that I am using automapper and want to achieve it using such.
Here is an example, I want to send back to the client in one chunk;
- The competencies that the employee has.
- The competencies that the employee requires for their job.
- The GAP, which is the difference between 1 and 2.
public class CompetencyRequirementsDto { [Key] public string CompanyId { get; set; } [Key] public string EmployeeNo { get; set; } public string JobId { get; set; } [Include] [Association("EmployeeCompetencies","CompanyId, EmployeeNo","CompanyId, EmployeeNo")] public IList<EmployeeCompetencyDto> EmployeeCompetencies { get; set; } [Include] [Association("JobCompetencies","JobId, CompanyId","JobId, CompanyId")] public IList<JobCompetencyDto> JobCompetencies { get; set; } [Include] [Association("CompetencyGap", "JobId, CompanyId", "JobId, CompanyId")] public IList<JobCompetencyDto> CompetencyGap { get; set; } } }
Now item 1 works fine, but 2 and 3 don't? What I have found is that my DTO is created ok server side but when it gets to the client CompetencyGap(even when it has no values) has
been given JobCompetencies values.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 ADO.Net 实体数据模型并针对它们使用 RIA 服务,那么您可以选择创建关联的元数据。
因此,为了在客户端获取引用实体,我们需要修改相应的元数据以及获取数据的域服务类的功能。
If you are using ADO.Net Entity data model and using RIA Services against them then you have got an option to create associated metadata.
So to get the reference entities at you client side we need to modify both the our corresponding meta-data and as well as well the function of the domain service class which is fetching your data .