c# - How to overwrite the implementation of a property created automatically in a partial class (T4 EF)? -
i need add logic when setting property datecreated
.
class partial , created automatically t4 template.
public partial class gaanalytic { public int analyticid { get; set; } public system.datetime datecreated { get; set; } }
i know if possible overwrite datecreated implementation, or other possible solutions.
you cannot override in strict sense of c# keyword property in same class. there workarounds.
just until ef did not support enumeration properties needed map integers , expose our application enumeration did kind of 'override' property introducing converted int enum , back. unfortunately need second name same value
//in generated partial public datetime datecreateddb { get; set; } //in second file contains partial of class public datetime datecreated { { // return converted datecreateddb } set { // set datecreateddb unconveted value } }
from database , ef point of view there datecreateddb column mapped , processed. on other hand in application use datecreated.
if use interfaces data model little bit simpler can provide explicit implementation interface property conversion.
the other thing can modify t4 template bit of hassle right tools not given out of box, doable , code cleaner.
Comments
Post a Comment