简体   繁体   中英

How can I make all properties virtual on entities generated by EF?

Normally on EF 6 when the entities are generated they put the properties in the style 'public type column'. Is there a way to increase a virtual in this properties like 'public virtual type column'?

I'm actually using the EF model design to generate the entities and this model have a file with extension .tt that's look like is the code to generate the entities class, but is very confusing.

I found the method that make the properties in .cs file in the T4 template (.tt file in EF Model Design).

public string Property(EdmProperty edmProperty)
{
    return string.Format(
        CultureInfo.InvariantCulture,
        "{0} virtual {1} {2} {{ {3}get; {4}set; }}",
        Accessibility.ForProperty(edmProperty),
        _typeMapper.GetTypeName(edmProperty.TypeUsage),
        _code.Escape(edmProperty),
        _code.SpaceAfter(Accessibility.ForGetter(edmProperty)),
        _code.SpaceAfter(Accessibility.ForSetter(edmProperty)));
}

I just added a 'virtual' in the string format.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM