I've searched but I guess I'm not exactly sure what to search on for this...
I am writing a data access layer for my application using the entity framework. I am performing a database first method so the entity data model is auto-generated.
So the model.context.cs file under the model.edmx contains this:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace com.MyCompany.AppPro.DAL
{
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
public partial class AppProEntities : DbContext
{
public AppProEntities()
: base("name=AppProEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<UserData> UserData { get; set; }
public virtual DbSet<UserKey> UserKey { get; set; }
}
}
I need to update this code to accept a connection string outside of this class. But when I update the model this file gets overwritten (which I'm warned about) in the comments. I can keep putting the code back in each time I update but there has to be a better way...
Is there any way I can add additional code into this file and have it retained on a DB schema update?