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.

Answers


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


Need Your Help

rails rspec controller action object method stub

ruby-on-rails rspec

I'm trying to test my controller #merge_with action. I want to test that @article is not nil, and gets assigned the article found in the database. Not sure why the test is failing, because the action

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.