Ian Warburton
Ian Warburton

Reputation: 15676

Adding a calculated property in Entity Framework when using an edmx file

I have a generated entity with a username and password property on it. I want these values encrypted when they're in the database and decrypted when they're read back in memory.

Ideally, outside of Entity Framework, my app's code wouldn't know about the encryption and decryption process.

Is it possible to tap into Entity Framework and do this conversion behind the scenes?

Also, this feature is to be added to an already existing code base so I don't really want to have to add a couple of new properties in a partial class because it would require having to update every usage of the already existing properties. And even if I did that then I'd still have the problem of stopping users from using the wrong versions.

Also if I could push the transformation further down into EF then I wouldn't have to worry about the perfomance hit of encrypting/decrypting every time a user users one of the properties.

Upvotes: 0

Views: 1182

Answers (1)

Paweł Staniec
Paweł Staniec

Reputation: 3181

You can use Partial Classes to accomplish that. There are several valuable resources on how to use use partial classes to extend / customize your objects. For example :

EF 4, how to add partial classes

http://msdn.microsoft.com/en-us/library/bb738612.aspx

Upvotes: 3

Related Questions