问题
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.
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.
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>
Could the OrderDto
then look like this?
public class OrderDto {
public string CustomerName { get; }
public string Customer { get; }
public string OrderItems { get; }
}
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
.
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.
回答1:
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.
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.
来源:https://stackoverflow.com/questions/37174311/tablecontroller-flatten-persistent-data-into-dto