views:

551

answers:

3

Hi,

I was wondering how people are handling the lack of Enum support in Entity Framework when dealing with WCF services?

Common practice seems to be to declare getter & setter in the entity property to private and then create a partial class for the entity and declare the enum property in there.

This is all fine and dandy but poses an issue for WCF services. I need the Enum definition on the client side and want this to happen through the automatic proxy generation. To do so I have to add the DataMember attribute to the Enum Property in the shared class, so it will be included in the serialization process.
However, when I call a the WCF method now, it serializes both, the (int) and (Enum) property, thus carrying redundant data and increasing message size. What's the best way to deal with this and how are other people handling this scenario?

Thanks,

Tom

A: 

We do not send EF objects over WCF.

We map the objects to DTO's (Data Transfer Objects) and send them over WCF.

This will change with EF 4, where there is support for POCO (Plain Old CLR Objects)

Shiraz Bhaiji
Thanks, this makes perfect sense. Would you continue to use DTO's with EF 4 or would you pursue the EF 4 POCO implementation? I'm just looking at some articles about it to see if it will work well
Tom Frey
A: 

So EF 4 don't support Enum...Let's find others solutions.

Let's say you have a OrderStatus enum, if you want to follow strict db design rules, you should create a OrderStatus table. You can then add info to your "enum" table such as:

  • Value (int or string)
  • Localizable description

Then you will create a foreign key in your table referencing it. This is one solution.

Now the other one is to replace the status id with a complex type:

http://devtalk.dk/CommentView,guid,d5dccc2a-5723-49b4-97d1-bf759b7f592d.aspx

Roubachof
+2  A: 

I agree that EF objects should not be sent over WCF. By doing so, you are exposing too much implementation detail of what is behind the WCF service.

To limit the amount of code you need to write to facilitate the transformation from EF objects to DTOs/POCOs exposed by the WCF service, take a look at Automapper.

mkedobbs
ty, +1 for the Automapper suggestion
Tom Frey