Different EF Property DataType than Storage Layer Possible?

Posted by dj_kyron on Stack Overflow See other posts from Stack Overflow or by dj_kyron
Published on 2010-03-27T20:52:29Z Indexed on 2010/03/27 20:53 UTC
Read the original article Hit count: 279

Hi,

I am putting together a WCF Data Service for PatientEntities using Entity Framework.

My solution needs to address these requirements:

  • Property DateOfBirth of entity Patient is stored in SQL Server as string. It would be ideal if the entity class did not also use the "string" type but rather a DateTime type. (I would expect this to be possible since we're abstracting away from the storage layer). Where could a conversion mechanism be put in place that would convert to and from DateTime/string so that the entity and SQL Server are in sync?. I cannot change the storage layer's structure, so I have to work around it.
  • WCF Data Services (Read-only, so no need for saving changes) need to be used since clients will be able to use LINQ expressions to consume the service. They can generate results based on any given query scenario they need and not be constrained by a single method such as GetPatient(int ID).

I've tried to use DTOs, but run into problem of mapping the ObjectContext to a DTO, I don't think that is theoretically possible...or too complicated if it is.

I've tried to use Self Tracking Entities but they require the metadata from the .edmx file if I'm correct, and this isn't allowing a different property data type.

I also want to add customizations to my Entity getter methods so that a property "MRN" of type "string" needs to have .Replace("MR~", string.Empty) performed before it is returned. I can add this to the getter methods but the problem with that is Entity Framework will overwrite that next time it refreshes the entity classes. Is there a permanent place I can put these?

Should I use POCO instead? How would that work with WCF Data Services? Where would the service grab the metadata?

© Stack Overflow or respective owner

Related posts about entity-framework

Related posts about sql-server