在 Northwind 示例的 Customer DTO 中,有一个字段 Email
是合成的——即它不是来自数据库。此处代码:https://github.com/ServiceStackApps/Northwind/blob/master/src/Northwind/Northwind.ServiceModel/Types/Customer.cs
但是在运行的例子中查看时,这个字段是不可见的: http://northwind.servicestack.net/query/customers
我注意到这个 DTO 有 [DataContract] 和 [DataMember] 注释,而大多数其他示例没有。
如何将合成字段添加到 AutoQuery?只需添加一个带有 pupulated getter 的方法就会给我一个错误,因为 ServiceStack 试图从数据库中获取它。是否应该使用“忽略”注释?或者最好的方法是将“DTO-for-database”和“DTO-for-the-service”分开,并以某种方式在它们之间使用 AutoMapper?
最佳答案
Is there an "Ignore" annotation that should be used?
正是这样,使用[Ignore]
忽略在OrmLite 中使用的字段或 AutoQuery而 [IgnoreDataMember]
是您想要在序列化中忽略该属性的时候。
Email
字段没有显示,因为它在 [DataContract]
类中没有 [DataMember]
字段是ignore fields in Serialization with ServiceStack.Text的方法之一.
关于ServiceStack AutoQuery 合成字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55246074/