Solved

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

Posted on 2011-03-01
4
1,545 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

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…
Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 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