Solved

WCF/Entity Framework - How To Get a Nice DataContract?

Posted on 2011-03-01
4
1,528 Views
Last Modified: 2012-05-11
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?
0
Comment
Question by:Silas2
  • 3
4 Comments
 
LVL 12

Expert Comment

by:FarWest
Comment Utility
If I understand correctly, you need your code to run regardless it will return what is in the records, or ignore it i.e. just like making try..catch with no handling just not to break,
anyway I think any you can put <Serializable> tag before the class, so even it is complex type it can be serialized and you code will run, to keep generated classes just inherit them in your code and adding the <Serializabe> or [Serializable] in c#, before declaration,

regards

0
 

Author Comment

by:Silas2
Comment Utility
No, I’m saying the classes made by edmx/EF file supposedly make data contracts for WCF, but doesn’t do a very good job and includes fields which can’t be transmitted, is there a clean way of using the auto-generated EF classes with WCF instead of having to hand-make classes for WCF DataContracts?
0
 

Accepted Solution

by:
Silas2 earned 0 total points
Comment Utility
I am doing a crude work-around which means I can leave the auto-generated code in the edmx, but just setting the Customer property to null before transmission over WCF, it doesn't lose the CustomerID property and the WCF is Ok, maybe that is the best compromise.
0
 

Author Closing Comment

by:Silas2
Comment Utility
best compromise
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This tutorial will show you how to add an attribute to an XML (http://en.wikipedia.org/wiki/XML) stream returned from a Windows Communication Foundation (http://en.wikipedia.org/wiki/Windows_Communication_Foundation) (WCF) Web Service.  Some knowled…
In previous Articles, we have discussed how we can upload a file using .asmx web service and isolated storage space. Here, in continuation to the topic, I am going to discuss how we can use WCF for the same purpose. Steps: 1.Create the silverli…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now