Solved

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

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

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…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

624 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