msawczyn / EFDesigner2022

Entity Framework visual design surface and code-first code generation for EF6, Core and beyond
MIT License
119 stars 21 forks source link

Store code in EFModel #18

Closed saigkill closed 2 years ago

saigkill commented 2 years ago

Is there any way, to store code (methods) to the EF model? So each regeneration that code will be applied by generation?

As example:

`[MaxLength(100)] [StringLength(100)] [NotMapped] public string DecryptedPassword { get { return Decrypt(Password); } set { Password = Encrypt(value); } }

private string Decrypt(string cipherText) { return EntityHelper.Decrypt(cipherText); }

private string Encrypt(string clearText) { return EntityHelper.Encrypt(clearText); }`

miehler commented 2 years ago

Since the generated classes are partial: Simply put your code in a seperate file for the same class.

msawczyn commented 2 years ago

@meihler is spot on. You can set the property as not being an AutoProperty; the generated code gives you a partial method to use as a hook to create/modify the value that is set or returned.