Overriding code-generated DbContext constructor

前端 未结 5 1247
花落未央
花落未央 2021-01-11 14:57

I\'m sure I\'ve done this before at some stage, but I can\'t figure out how to now! My scenario:

// This is generated from EDMX
public partial class HOLDbEnt         


        
5条回答
  •  再見小時候
    2021-01-11 15:33

    The best I can suggest is a factory method:

    private HOLDbEntities(string contextName) : base(contextName) { }
    
    public static HOLDbEntities Create() {
        return new HOLDbEntities(ContextName);
    }
    

    and use HOLDbEntities.Create() rather than new HOLDbEntities().

提交回复
热议问题