Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-03-01
4
Medium Priority
?
1,556 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
ID: 35007111
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
ID: 35007935
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
ID: 35008151
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
ID: 35135806
best compromise
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Loops Section Overview

972 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