如果创建一个DomainService,暴露一个实体,你可以访问聚合实体吗? [英] If you create a DomainService, exposing an entity, can you access aggregate entities?

查看:136
本文介绍了如果创建一个DomainService,暴露一个实体,你可以访问聚合实体吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您创建了一个RIA DomainService,并在其中包含一个 Person (如下所示)实体,您可以访问该对象上的聚合实体吗?

$ b例如,如果我有这样的实体(请记住,这是一个天真的表示,它们通过EF4设计师建模):



public class Person
{
string FirstName {get;组; }
PhoneNumber {get;组; }
}

public class PhoneNumber
{
public string AreaCode {get;组; }
public string Trunk {get;组; }
public string Number {get;组;
}

如果我包含 Person 在创建PeopleDomainService时,客户端是否可以访问 PhoneNumber (并修改它)?

解决方案

是的,您可以引入相关实体。



在PeopleDomainService.metadata.cs文件中,查找PersonMetadata类。在PhoneNumbers属性上,添加Include属性:

  [Include]:
public EntityCollection< PhoneNumber> PhoneNumbers {get;组;

在PeopleDomainService.cs中,查找GetPersons函数并修改它以包含PhoneNumbers:

  public IQueryable< Person> GetPersons()
{
return this.ObjectContext.Persons.Include(PhoneNumbers);
}

您可以在MSDN上找到更多详细信息> 演练:参观RIA服务>显示相关数据


Say you create an RIA DomainService and you include a Person (shown below) entity in it, can you access aggregate entities on that object?

For instance, if I have entities like so (keep in mind that this is a naive representation, they are modeled via the EF4 designer):

public class Person
{
    string FirstName { get; set; }
    PhoneNumber { get; set; }
}

public class PhoneNumber
{
    public string AreaCode { get; set; }
    public string Trunk { get; set; }
    public string Number { get; set; }
}

If I include Person when creating the PeopleDomainService, can the client access the PhoneNumber on it (and modify it)?

解决方案

Yes, you can bring in related entities.

In the PeopleDomainService.metadata.cs file, look for the PersonMetadata class. On the PhoneNumbers property, add the "Include" attribute:

[Include]:
public EntityCollection<PhoneNumber> PhoneNumbers { get; set; }

In the PeopleDomainService.cs, look for the GetPersons function and modify it to include the PhoneNumbers:

public IQueryable<Person> GetPersons()
{
    return this.ObjectContext.Persons.Include("PhoneNumbers");
}

You can find more details on MSDN > Walkthrough: Taking a Tour of RIA Services > Displaying Related Data

这篇关于如果创建一个DomainService,暴露一个实体,你可以访问聚合实体吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆