Forked from lprichar/LeesStoreDbContextModelCreatingExtensions.cs
Created
December 14, 2020 17:57
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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