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>
Für den Kontext habe ich den folgenden 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");
});
Die Tabellen haben eine n: M -Beziehung von Benutzern mit Rollen von den Tabellenrollen roles_users
und Rollen , location und Berechtigungen a n: M -Beziehung mit table uproles uproles coces. Positionen und in den Positionen Die Berechtigungen , aber dieser Code gibt mir den Fehler von
Spalte R.roles_Permissions_Location_Zone existiert nicht. so sehr im Voraus
Ich versuche, den Kontext mehrerer Entitäten in [b] Entity Framework zu erstellen. [/b] von [b] c#[/b] (.NET).[code]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> Für den Kontext habe ich den folgenden 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("location_zones"); }); [/code] Die Tabellen haben eine n: M -Beziehung von Benutzern mit Rollen von den Tabellenrollen roles_users und Rollen , location und Berechtigungen a n: M -Beziehung mit table uproles uproles coces. Positionen und in den Positionen Die Berechtigungen , aber dieser Code gibt mir den Fehler von
Spalte R.roles_Permissions_Location_Zone existiert nicht. so sehr im Voraus
Ich versuche, den Kontext mehrerer Entitäten im Entitäts -Framework von C# .NET zu erstellen.
Ich habe die folgenden Entitäten:
public class User {
public int id { get; set; } // id int4 primary...
Ich versuche derzeit, einen Einheit /Integrationstest zu schreiben, indem ich den Anbieter von Memory -Datenbank unter Verwendung eines Memory -Datenbankanbieters zu schreiben habe. Entity Framework...
Ich habe eine Reihe von hochkomplexen vielen zu vielen Beziehungen, die ich gleichzeitig abfragen möchte, mit einigen zusätzlichen Komplexitäten, einschließlich zusammengesetzter Schlüssel und nicht...