0

I am adding these lines to my SuburbanPortalModel.Context.cs:

  public SuburbanPortalEntities(string nameOrConnectionString)
    : base(nameOrConnectionString)
  {
  }

When I update the Model, this is being wiped out.

Here it is in the class:

public partial class SuburbanPortalEntities : DbContext
{
    public SuburbanPortalEntities()
        : base("name=SuburbanPortalEntities")
    {
    }

    public SuburbanPortalEntities(string nameOrConnectionString)
      : base(nameOrConnectionString)
    {
    }

Where do I need to put this so it is not wiped out on each update?

ErocM
  • 4,505
  • 24
  • 94
  • 161

1 Answers1

1

Your changes are being wiped out because SuburbanPortalModel.Context.cs is auto generated by the .tt file.

For renaming the connection string that EF is using, check this SO answer

If you still wanted to persist your changes though, you would leverage the fact that the generated DbContext is a partial class.

So create a new SuburbanPortalEntities class (in a separate file of course) and put your changes there.

public partial class SuburbanPortalEntities : DbContext
{

    public SuburbanPortalEntities(string nameOrConnectionString)
      : base(nameOrConnectionString)
    {
    }

    //public void MyCustomDoFoo(){

    //}

} 
Community
  • 1
  • 1
HaveThunk
  • 230
  • 1
  • 7