New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ASP.NET boilerplate new module's dbcontext recreate abp main tables #6910
Comments
Because these base entities are defined in AbpZeroDbContext. Have you tried inheriting from DbContext only ? |
@ismcagdas yes I tried and then an exception is thrown when adding an migration: |
@ismcagdas using AbpDbContext and DbContext gives the same exception |
This is not basically related to ASP.NET Boilerplate but if you can provide a reproduction project, we can taka a look. |
@ismcagdas can I ask what is the best approach, to make central dbContext in main profgram, or to have each module define its dbcontext. With the case of central db context, this will make main project depends on all new modules .. and that's okay but if I want to use entities from main program inside the new modules that's will make the new modules depends on main program and that's not possible with central dbContext .. I am a little confused in this problem |
I haven't tried this approach before. Maybe this sample can help you https://github.com/aspnetboilerplate/aspnetboilerplate-samples/tree/master/MultipleDbContextEfCoreDemo |
I created an ASP.NET boilerplate multi-tenancy startup template, 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{}
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 Messages { get; set; }
}
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'
The text was updated successfully, but these errors were encountered: