WCF/Entity Framework - How To Get a Nice DataContract?
Posted on 2011-03-01
After naively spending 2hs working out why an EF object wasn’t getting transferred over the wires thru WCF, using reflection and removing field by field, I had the ‘doh’ moment that the offending fields where the related ‘composite’ fields, i.e. say Invoice object, the field WCF was choking on was Customer, representing Customer object as opposed to CustomerID, the actual field in the Invoice table.
The structure of the project is DataLIB, with edmx, WCF with IService contract, and using the DataLIB/edmx for the [DataContract].
Obviously, I could hand code the DataContract, but I was hoping to stay with the auto-generated edmx files, verbose though they may look.
My question is…what is the elegant way of generating the edmx, and using that for a [DataContract]/[DataMember] source, but stopping fields (showstoppers + superfluous ones) from being part of the WCF contract without having an auto-generated EF + a hand-coded contract?