TableController:拼合持久数据到DTO [英] TableController: Flatten persistent data into DTO

查看:224
本文介绍了TableController:拼合持久数据到DTO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Azure应用服务的移动应用程序。我想了解我的选择,使用 TableController 揭露复杂的域对象给客户。我使用的目标 TableController 是利用客户端的查询和离线同步的。

I'm new to Azure App Service mobile apps. I'm trying to understand my options for using TableController to expose complex domain objects to clients. My goal of using TableController is to take advantage of client-side querying and offline sync.

表控制器设计用于简单的DTO执行CRUD操作。所以我试图找出一个复杂的域模型如何被暴露作为排序的DTO的是 TableController 是专为。

Table controllers are designed to perform CRUD operations on simple DTOs. So I'm trying to figure out how a complex domain model could be exposed as the sort of DTOs that TableController is designed for.

我读过<一个href=\"https://blogs.msdn.microsoft.com/azuremobile/2014/05/19/mapping-between-database-types-and-client-types-in-the-net-backend-using-automapper/\"相对=nofollow>这个帖子这也解释了 MappedEntityDomainManager 。这个例子显示的DTO和持久对象之间的一个相当简单的映射。但是,如果我希望我的映射更加复杂?

I've read this post which explains MappedEntityDomainManager. That example shows a fairly simple mapping between DTOs and persistent objects. But what if I want my mapping to be more complex?

例如,假设我有持续性的类型如下:

For example, let's say I have persistent types like this:

public class Order {
    public Customer Customer { get; set; }
    public IList<OrderItem> OrderItems { get; }
}

public class Customer {
    public string Name { get; set; }
    public string TelephoneNumber { get; set; }
}

public class OrderItem { ... }

和我有声明如下表控制器:

And I have a table controller declared like this:

public class OrderController : TableController<OrderDto>

莫非 OrderDto 然后这个样子?

public class OrderDto {
    public string CustomerName { get; }
    public string Customer { get; }
    public string OrderItems { get; }
}

的映射将是如下。在 Order.Customer.Name 属性被压扁成 OrderDto.CustomerName 。完整的客户对象序列化为 OrderDto.Customer 。和 Order.OrderItems 列表序列化为 OrderDto.OrderItems

The mappings would be as follows. The Order.Customer.Name property is flattened into OrderDto.CustomerName. The complete Customer object is serialized into OrderDto.Customer. And the Order.OrderItems list is serialized into OrderDto.OrderItems.

能这样复杂的映射与 MappedEntityDomainManager 做了什么?如果没有,那么怎么能做到呢?我知道<一个href=\"https://blogs.msdn.microsoft.com/azuremobile/2014/06/18/insertupdate-data-with-1n-relationship-using-net-backend-azure-mobile-services/\"相对=nofollow>利用 $展开 ,但我担心这可能是不支持的黑客攻击,而不是推荐的方法。

Can this sort of complex mapping be done with MappedEntityDomainManager? If not then how could it be done? I know about leveraging $expand, but I worry that may be an unsupported hack rather than the recommended approach.

推荐答案

要做到这一点,最好的方法是使用Automapper。该博客文章是一个简单的例子,但可以使用automapper做的非常复杂的映射。

The best way to do this is to use Automapper. The blog post was a simple example, but you can do very complex mapping using automapper.

下面是一个更复杂的例子:<一href=\"https://github.com/paulbatum/FieldEngineerLite/blob/master/FieldEngineerLite.Service/Controllers/JobController.cs\" rel=\"nofollow\">https://github.com/paulbatum/FieldEngineerLite/blob/master/FieldEngineerLite.Service/Controllers/JobController.cs.这对Azure的移动服务,但相同的概念适用于Azure的移动应用。你只需要改变命名空间。

Here's a more complex example: https://github.com/paulbatum/FieldEngineerLite/blob/master/FieldEngineerLite.Service/Controllers/JobController.cs. It's for Azure Mobile Services, but the same concept applies to Azure Mobile Apps. You just need to change the namespaces.

这篇关于TableController:拼合持久数据到DTO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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