WCF Contracts from Entity Framework?

后端 未结 4 2030
予麋鹿
予麋鹿 2021-02-14 06:52

I\'ve been coming up with a lot of dead ends on this question. Supposedly, .NET 3.5 SP1 has Support for ADO.NET Entity Framework entities in WCF contracts. But when I look for

4条回答
  •  -上瘾入骨i
    2021-02-14 07:52

    Some more detail in response to comments:

    There are several problems with the classes generated by EF. I'm looking now at an AdventureWorks example with SalesOrderHeader and SalesOrderDetail. The SalesOrderDetail entity has both "SalesOrderHeader" and "SalesOrderHeaderReference" properties, both marked as DataMembers. This looks like a bug, since the "SalesOrderHeader" property is also marked [XmlIgnore] and [SoapIgnore].

    Also, consider whether you want to serialize the link back to the parent SalesOrderHeader in the first place. Besides, what exactly should be serialized? SOAP doesn't support references in an interoperable manner.

    Finally, the base classes of the entities are also data contracts. Yet they have nothing to do with the data you are returning - they are purely an implementation artifact.

    In short, Microsoft screwed up on this one. They didn't think it through.

    About ways to generate the DTO classes, I suggest looking into various code generation tools, like CodeSmith. You can write code to do this yourself; I did so in my previous position. The nice thing about generating the DTO is that you also get to generate the methods to translate to and from the DTO.

    As to overhead, the overhead of moving some data around in memory is nothing compared to the amount of time it's going to take to send the data over a network!

提交回复
热议问题