项目场景:
ABP项目执行数据库迁移
问题描述:
Unable to determine the relationship represented by navigation 'XXX' of type 'XXX'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.原因分析:
在XXXDbContext中OnModelCreating 下缺少对初始化的配置。
解决方案:
/// <summary>
/// Fluent API
/// </summary>
public class UserEntityConfig : IEntityTypeConfiguration<User>
{
public void Configure(EntityTypeBuilder<User> builder)
{
// ......
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
//继承自IEntityTypeConfiguration<>的各实体 Fluent API
modelBuilder.ApplyConfigurationsFromAssembly(typeof(XXXCoreModule).Assembly);
}