I want to use EF Code first migrations in Azure functions project which is class library .net 4.6.2
with EF 6.2.0
. I added db context and entities. When i try to run enable-migrations
or add-migration
by setting this class library as default project then getting below error. I don't have any web projects in the solution.
Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject' in assembly 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable." At C:\Users\xxxxx-win.nuget\packages\entityframework\6.2.0\tools\EntityFramework.psm1:720 char:5 + $domain.SetData('project', $project) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : SerializationException
But when i run the project then it automatically creates __MigrationHistory
table with InitialCreate
entry. But i can't see this migration file anywhere in the solution.
dbcontext file for reference.
public class TestDbContext : DbContext
{
public TestDbContext(string cs)
: base(cs)
{
}
public TestDbContext() :
base(ConfigurationManager.ConnectionStrings["sql_connection"].ConnectionString)
{
Database.SetInitializer(new TestDBInitializer());
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<TestRaw>().ToTable("TestRaw");
modelBuilder.Entity<TestRequest>().ToTable("TestRequest");
}
public virtual DbSet<TestRaw> TestRaw { get; set; }
public virtual DbSet<TestRequest> TestRequest { get; set; }
}
public class TestDBInitializer : CreateDatabaseIfNotExists<TestDbContext>
{
protected override void Seed(TestDbContext context)
{
base.Seed(context);
}
}
Also, azure functions doesn't use app.config. So not sure where EF related dependencies are registered? Can we use EF Code first migrations with Azure functions? If yes, how to see migrations folder and relevant files ? do i need to take care anything related to migrations while deploying to functionapp?