Skip to content

Instantly share code, notes, and snippets.

@Diaskhan
Created April 20, 2019 09:55
Show Gist options
  • Save Diaskhan/cb5544d0557c6001d1c4c6ac2b656c98 to your computer and use it in GitHub Desktop.
Save Diaskhan/cb5544d0557c6001d1c4c6ac2b656c98 to your computer and use it in GitHub Desktop.
dbcontext lambda
rowanmiller commented on 31 Jul 2015
@sonofsam I think rather than putting the ModelBuilder in DI you want to construct your model and set it on the DbContextOptions that are registered in DI.
var builder = new ModelBuilder();
// all the code to configure your model
var model = builder.Model;
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<MyDbContext>(options =>
{
options.UseSqlServer("<connection string>");
options.UseModel(model);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment