I am using this sample project (https://github.com/imranbaloch/ASPNETIdentityWithOnion) as my application architecture, in this sample the core is completly decoplied from the infrastrure including the identity framework.
In this sample the author has used the adapter pattern to decouple core identity classes (IdentityUser, IdentityRole ... ) and provide classes like them in the Core layer.
Now the issue in this sample project is that the Domain model (Product, Images) are not linked with the dummy classes (AppUser, ApplicationRole, AppliationUserRoles, ...) that mimics the Identity ones.
Then I have modified the code to added the reference to AppUser
public sealed class Image : BaseEntity
{
public Image()
{
Products = new HashSet<Product>();
}
public string Path { get; set; }
public AppUser AppUser { get; set; } // The Added Reference ...
public ICollection<Product> Products { get; set; }
}
If I put the "AppUser" navigation property inside the "Image" class, the created database will have FOUR new tables other than the default FIVE tables of the identity framework.
I need to merge these tables into the default ones. how ?
EDIT:
This is the Identity Models that resides in the Data Layer (which I can not reference from the core).
public class ApplicationIdentityUser :
IdentityUser<int, ApplicationIdentityUserLogin, ApplicationIdentityUserRole, ApplicationIdentityUserClaim>, IDomainUser {
public ApplicationIdentityUser()
: base() {
Images = new HashSet<Image>();
}
public string Name { get; set; }
public virtual ICollection<Image> Images { get; set; }
}
public class ApplicationIdentityRole : IdentityRole<int, ApplicationIdentityUserRole>
{
public ApplicationIdentityRole(){}
public ApplicationIdentityRole(string name){Name = name;}
}
public class ApplicationIdentityUserRole : IdentityUserRole<int> {}
public class ApplicationIdentityUserClaim : IdentityUserClaim<int>{}
public class ApplicationIdentityUserLogin : IdentityUserLogin<int>{}
Also this is my model builder in the OnModelCreating method:
modelBuilder.Entity<Image>()
.Property(e => e.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
modelBuilder.Entity<Image>()
.HasMany(e => e.Products)
.WithRequired(e => e.Image)
.WillCascadeOnDelete(false);
modelBuilder.Entity<ApplicationIdentityUser>()
.Property(e => e.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
modelBuilder.Entity<ApplicationIdentityRole>()
.Property(e => e.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
modelBuilder.Entity<ApplicationIdentityUserClaim>()
.Property(e => e.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
Users
andRoles
and other, so EF creates 2 sets of tables for you. Check for that. – TourmalineIDbset
s look like in ApplicationDbContext? – Tourmaline