I created an ASP.NET boilerplate multi-tenancy startup template from download page in aspboilerplate website, then created new module in src folder with Application, Core, Entity Framework Core, and Web projects that Main project depends on.
The new module has its own dbcontext. I put new entities in the new module that have navigation properties to User table in the main module. Problem is every time I add new migration to the new module , all the tables of abp are recreated, I want just the new tables to be added with the right foreign keys to the main tables.
ChatUser in the new module:
public class ChatUser : AbpUser<ChatUser>
{}
The new entity in the new module :
public class Message : CreationAuditedEntity, IMustHaveTenant
{
public string Content { get; set; }
public int TenantId { get; set; }
public long SenderId { get; set; }
[ForeignKey(nameof(SenderId))]
public virtual ChatUser User { get; set; }
}
And the new module's dbContext is:
public class ChatDbContext : AbpZeroDbContext<ChatTenant, ChatRole, ChatUser, ChatDbContext>
{
public DbSet<Message> Messages { get; set; }
public ChatDbContext(DbContextOptions<ChatDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
RegisterConfigurations(modelBuilder);
}
}
I don't know where the problem is. I tried to put the dbContext in new module as:
public class ChatDbContext : AbpDbContext
but then an exception happens when adding migration:
Unable to create a 'DbContext' of type ''. The exception 'Unable to determine the relationship represented by navigation 'ChatUser.CreatorUser' of type 'ChatUser'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'