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
Solved

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

Posted on 2011-03-01
4
1,537 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

807 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