У меня есть следующие объекты: < /p>
Код: Выделить всё
public class User {
public int id { get; set; } // id int4 primary key,
public string name { get; set; } // name varchar (50) not null unique,
public string? first_name { get; set; } // first_name varchar (50) null,
public string? last_name { get; set; } // last_name varchar (50) null,
public string password_hash { get; set; } // password_hash text not null,
public List roles { get; set; }
}
public class Role {
public int id { get; set; } // id int4 primary key,
public string name { get; set; } // name varchar (50) not null unique,
public string? description { get; set; } // description varchar (255),
public List users { get; set; }
public List locations_zones { get; set; }
}
public class LocationZone {
public int id { get; set; } // id int4 primary key,
public string name { get; set; } // id_location_zone varchar(50) not null,
public string? description { get; set; } // description varchar(255) null,
public List locations { get; set; }
public List roles { get; set; }
public List
permissions { get; set; }
}
public class Permission {
public int id { get; set; } // id int4 primary key,
public string name { get; set; } // name varchar (50) not null unique,
public string? description { get; set; } // description varchar (255),
public List locations_zones { get; set; }
}
public class RolePermission {
public int id_role { get; set; } // id_role int4,
public int id_location_zone { get; set; } // id_location_zone int4,
public int id_permission { get; set; } // id_permission int4,
public List roles { get; set; }
public List location_zones { get; set; }
public List permissions { get; set; }
}
< /code>
Для контекста у меня есть следующий код: < /p>
model_builder.Entity(entity => {
entity.HasKey(_ => new { _.id }); entity.ToTable("users");
entity.HasMany(_ => _.roles).WithMany(_ =>_.users)
.UsingEntity(
"users_roles",
j => j.HasOne().WithMany().HasForeignKey(_ => _.id_role),
j => j.HasOne().WithMany().HasForeignKey(_ => _.id_user));
});
model_builder.Entity(entity => {
entity.HasKey(_ => new { _.id }); entity.ToTable("roles");
entity.HasMany(_ => _.locations_zones).WithMany(_ => _.roles)
.UsingEntity( "roles_permissions",
j => { j.ToTable("roles_permissions");
j.HasKey(rp => new { rp.id_role, rp.id_location_zone, rp.id_permission });
j.HasOne().WithMany().HasForeignKey(_ => _.id_location_zone);
j.HasOne().WithMany().HasForeignKey(_ => _.id_role);
});
});
model_builder.Entity(entity => {
entity.HasKey(_ => new { _.id });
entity.ToTable("location_zones");
});
и роли , location и разрешения a n: m in saturning с таблицами roles_permisions . Локации и в локациях разрешения , но с помощью этого кода дают мне ошибку
column r.roles_permissionsid_location_zone. /> Большое спасибо заранее < /p>
Подробнее здесь: https://stackoverflow.com/questions/796 ... ral-tables