Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

Created Issue: Migrations :: we create invalid migration configuration for generic DbContext [1613]

$
0
0
Consider the following:

```
public class BaseUser
{
public int Id { get; set; }
public string Name { get; set; }
}

public class DerivedUser : BaseUser
{
public string Credentials { get; set; }
}

public class MyContext<TUser> : DbContext where TUser : BaseUser
{
public DbSet<TUser> Users { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<TUser>().ToTable("MyTable");
}
}
```

When trying to Enable-Migrations, we get this output:

```
internal sealed class Configuration : DbMigrationsConfiguration<ConsoleApplication1.MyContext`1>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
}

protected override void Seed(ConsoleApplication1.MyContext`1 context)
{
}
}
```

which is broken. We should either fix this or provide a guidance to a user upon executing Enable-Migrations (e.g. derive from the generic DbContext and enable migrations for that context)

Viewing all articles
Browse latest Browse all 10318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>