How to override a partial class property
If you can change code generator, you can easy "emulate" it ("overriding" default values) using extrimely powerfull partial methods.
https://msdn.microsoft.com/en-us/library/wa80x488.aspx
While you can't override the Entity Framework base classes, there is a work around. In the .edmx model (for DB first, direct in entities if code first) on the propery you want to 'override' change the Getter / Setter to private and rename the property. Then create the partial class with the property using the public name, which will no longer conflict.
In the public partial class property you will be able to access the private renamed property if needed.
Partial classes have nothing to do with inheritance, and override
is entirely about inheritance.
The partial
keyword on a class just means that it can be declared multiple times in the same assembly. It's exactly the same as if you copied every part of every partial class
into the same file and removed the partial
keyword. Since you can't define the same property/function/etc twice in the same class, you can't define it twice in two separate parts of the same class, even with the partial
keyword.
override
, on the other hand, is used in derived classes to indicate that they're replacing the functionality of the base class they inherit from. If it doesn't explicitly inherit, it inherits from object
, which lets you override ToString()
(among others).
Your best options to do what you want are either to use a custom T4 template to generate the encrypt/decrypt logic, or to set the encrypted properties to protected
or private
in the designer and manually add public
versions which do the decryption.