How to expose part of Entity as DataContract?

后端 未结 2 1781
粉色の甜心
粉色の甜心 2021-01-20 17:40

Up to now, when working with WCF, I have always been exposing the whole either EF generated entities, or POCOs(by modifying the T4 template to include DataContract and DataM

2条回答
  •  轮回少年
    2021-01-20 18:24

    First of all you should never expose the whole entity as a data contract, as it is a domain object, not the data transfer object. Not just in that particular situation. Never. Now you're creating a confusing inconsistency between entities which do have a DTO and those which don't.

    Returning to a question: AutoMapper seems to be pretty ok. You just have to define 2 mappings. And probably Ignore() missing properties when mapping back to entity.

提交回复
热议问题