servicestackservicestack-autoquery

ServiceStack AutoQuery synthetic field


In the Northwind example's Customer DTO there is a field Email that is synthetic -- i.e. it doesn't come from the database. Code here: https://github.com/ServiceStackApps/Northwind/blob/master/src/Northwind/Northwind.ServiceModel/Types/Customer.cs

But when viewing this in the running example, this field is not visible: http://northwind.servicestack.net/query/customers

I've noticed this DTO has [DataContract] and [DataMember] annotations, whereas most other examples do not.

How do I add synthetic fields to an AutoQuery? Just adding one with a pupulated getter gives me an error, as ServiceStack tries to fetch it from the database. Is there an "Ignore" annotation that should be used? Or would the best way be to separate the "DTO-for-database" and the "DTO-for-the-service", and use AutoMapper between them somehow?


Solution

  • Is there an "Ignore" annotation that should be used?

    Exactly that, use [Ignore] to ignore the field from being used in OrmLite or AutoQuery whilst [IgnoreDataMember] is when you want to ignore the property in serialization.

    The Email field doesn't get shown because it doesn't have a [DataMember] field in a [DataContract] class which is one of the ways to ignore fields in Serialization with ServiceStack.Text.