ServiceStack AutoQuery synthetic field

。_饼干妹妹 提交于 2020-01-04 01:38:09

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/55246074/servicestack-autoquery-synthetic-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!