Open Closed

Many to one and one to one relation issue #1379


User avatar
0
sergey.sorokin.kz@gmail.com created
  • ABP Framework version: v4.3.0
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace: No
  • Steps to reproduce the issue:

I have the following AbpUser class:

public class AppUser : FullAuditedAggregateRoot<Guid>, IUser
{
        ...

        public Guid? SettingId { get; set; }
        public virtual ICollection<UserClient> Clients { get; set; }

        private AppUser()
        {
            Clients = new List<UserClient>();
        }
}

UserClient is defined like this:

public class UserClient : Entity<Guid>
{
    public string Name { get; set; }
    public Guid UserId { get; set; }

}

When I add the relation one to one for Settings and many to one between AbpUser and UserClients, there is no relation in the migration class at all.

builder.Entity<AppUser>(b =>
{
    b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "Users"); //Sharing the same table "AbpUsers" with the IdentityUser

    b.ConfigureByConvention();
    b.ConfigureAbpUser();
    b.ConfigureExtraProperties();

    ...

    b.HasOne<Setting>().WithOne().HasForeignKey<AppUser>(x => x.SettingId);
    b.HasMany(x => x.Clients).WithOne().HasForeignKey(x => x.UserId);
});

Reading the article didn't resolve the migration issue for me. How do I add 2 relations (one AbpUser should have many UserClients) and (one ApbUser has one Setting) to get correct relations in the migration?


4 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    What's Exception message and stack trace?

    Can you repro the problem use the template project then share it with me? liming.ma@volosoft.com

  • User Avatar
    0
    sergey.sorokin.kz@gmail.com created

    Hi, Liming,

    There is no exception. The only worng this is that the generated migration doesn't contain the foreing key creation code.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you repro the problem use the template project then share it with me? liming.ma@volosoft.com

  • User Avatar
    0
    ServiceBot created
    Support Team Automatic process manager

    This question has been automatically marked as stale because it has not had recent activity.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09