Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save robinthomas/16a40cc17ab0a68cf75f5f3a26759716 to your computer and use it in GitHub Desktop.

Select an option

Save robinthomas/16a40cc17ab0a68cf75f5f3a26759716 to your computer and use it in GitHub Desktop.
Auto Entity Model Adding During DB Context Creation via Reflection for ABP.IO
var allDbSets = typeof(LeesStoreDbContext).GetProperties()
.Where(p => p.PropertyType.Name == "DbSet`1")
.Select(p => new
{
Type = p.PropertyType.GetGenericArguments()[0],
p.Name
})
.Where(p => p.Name != nameof(LeesStoreDbContext.Users));
foreach (var property in allDbSets)
{
var type = property.Type;
builder.Entity(type, i =>
{
i.ToTable(LeesStoreConsts.DbTablePrefix + property.Name, LeesStoreConsts.DbSchema);
i.ConfigureByConvention();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment