add lazy loading for entities
This commit is contained in:
@@ -21,7 +21,7 @@ namespace ReallifeGamemode.Server.Entities
|
||||
|
||||
[ForeignKey("User")]
|
||||
public int UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
public virtual User User { get; set; }
|
||||
|
||||
public string Reason { get; set; }
|
||||
public string BannedBy { get; set; }
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace ReallifeGamemode.Server.Entities
|
||||
|
||||
[ForeignKey("User")]
|
||||
public int UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
public virtual User User { get; set; }
|
||||
|
||||
public bool Gender { get; set; }
|
||||
public byte Father { get; set; }
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace ReallifeGamemode.Server.Entities
|
||||
|
||||
[ForeignKey("User")]
|
||||
public int UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
public virtual User User { get; set; }
|
||||
|
||||
public bool Duty { get; set; }
|
||||
|
||||
|
||||
@@ -31,6 +31,6 @@ namespace ReallifeGamemode.Server.Entities
|
||||
|
||||
[ForeignKey("FactionId")]
|
||||
public int? FactionId { get; set; }
|
||||
public Faction Faction { get; set; }
|
||||
public virtual Faction Faction { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace ReallifeGamemode.Server.Entities
|
||||
|
||||
[ForeignKey("Faction")]
|
||||
public int FactionId { get; set; }
|
||||
public Faction Faction { get; set; }
|
||||
public virtual Faction Faction { get; set; }
|
||||
|
||||
public bool Gender { get; set; }
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace ReallifeGamemode.Server.Entities
|
||||
public int Id { get; set; }
|
||||
[ForeignKey("Faction")]
|
||||
public int FactionId { get; set; }
|
||||
public Faction Faction { get; set; }
|
||||
public virtual Faction Faction { get; set; }
|
||||
[StringLength(12)]
|
||||
public string Bic { get; set; }
|
||||
[StringLength(32)]
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace ReallifeGamemode.Server.Entities
|
||||
|
||||
|
||||
public int FactionId { get; set; }
|
||||
public Faction Faction { get; set; }
|
||||
public virtual Faction Faction { get; set; }
|
||||
|
||||
public Faction GetFaction()
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace ReallifeGamemode.Server.Entities
|
||||
{
|
||||
[ForeignKey("Faction")]
|
||||
public int? FactionId { get; set; }
|
||||
public Faction Faction { get; set; }
|
||||
public virtual Faction Faction { get; set; }
|
||||
|
||||
public Faction GetFaction()
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace ReallifeGamemode.Server.Entities
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
public Group Group { get; set; }
|
||||
public virtual Group Group { get; set; }
|
||||
|
||||
public int Balance { get; set; }
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace ReallifeGamemode.Server.Entities
|
||||
{
|
||||
public class GroupVehicle : ServerVehicle
|
||||
{
|
||||
public Group Group { get; set; }
|
||||
public virtual Group Group { get; set; }
|
||||
|
||||
[ForeignKey("Group")]
|
||||
public int? GroupId { get; set; }
|
||||
|
||||
@@ -21,11 +21,11 @@ namespace ReallifeGamemode.Server.Entities.Logs
|
||||
|
||||
[ForeignKey("Victim")]
|
||||
public int VictimId { get; set; }
|
||||
public User Victim { get; set; }
|
||||
public virtual User Victim { get; set; }
|
||||
|
||||
[ForeignKey("Killer")]
|
||||
public int? KillerId { get; set; }
|
||||
public User Killer { get; set; }
|
||||
public virtual User Killer { get; set; }
|
||||
|
||||
public float VictimPositionX { get; set; }
|
||||
public float VictimPositionY { get; set; }
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace ReallifeGamemode.Server.Entities
|
||||
|
||||
[ForeignKey("User")]
|
||||
public int? UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
public virtual User User { get; set; }
|
||||
|
||||
public string Caption { get; set; }
|
||||
public string Content { get; set; }
|
||||
|
||||
@@ -19,7 +19,6 @@ namespace ReallifeGamemode.Server.Entities
|
||||
public class ShopVehicle : ServerVehicle
|
||||
{
|
||||
[ForeignKey("Shop")]
|
||||
public int? ShopId { get; set; }
|
||||
public int BusinessId { get; set; }
|
||||
public int Price { get; set; }
|
||||
|
||||
|
||||
@@ -44,24 +44,26 @@ namespace ReallifeGamemode.Server.Entities
|
||||
|
||||
[ForeignKey("Character")]
|
||||
public int? CharacterId { get; set; }
|
||||
public Character Character { get; set; }
|
||||
public virtual Character Character { get; set; }
|
||||
|
||||
[ForeignKey("Ban")]
|
||||
public int? BanId { get; set; }
|
||||
public Ban Ban { get; set; }
|
||||
public virtual Ban Ban { get; set; }
|
||||
|
||||
public int? FactionId { get; set; }
|
||||
public Faction Faction { get; set; }
|
||||
public virtual Faction Faction { get; set; }
|
||||
|
||||
public bool FactionLeader { get; set; }
|
||||
|
||||
public int? FactionRankId { get; set; }
|
||||
public FactionRank FactionRank { get; set; }
|
||||
public virtual FactionRank FactionRank { get; set; }
|
||||
|
||||
public Group Group { get; set; }
|
||||
public virtual Group Group { get; set; }
|
||||
|
||||
public GroupRank GroupRank { get; set; }
|
||||
|
||||
public virtual Job Job { get; set; }
|
||||
|
||||
public FactionRank GetFactionRank()
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace ReallifeGamemode.Server.Entities
|
||||
public int Id { get; set; }
|
||||
[ForeignKey("User")]
|
||||
public int UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
public virtual User User { get; set; }
|
||||
[StringLength(12)]
|
||||
public string Bic { get; set; }
|
||||
[StringLength(32)]
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace ReallifeGamemode.Server.Entities
|
||||
|
||||
[ForeignKey("User")]
|
||||
public int UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
public virtual User User { get; set; }
|
||||
|
||||
public int Amount { get; set; }
|
||||
public int Slot { get; set; }
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace ReallifeGamemode.Server.Entities
|
||||
{
|
||||
[ForeignKey("User")]
|
||||
public int UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
public virtual User User { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace ReallifeGamemode.Server.Entities
|
||||
|
||||
[ForeignKey("Vehicle")]
|
||||
public int ServerVehicleId { get; set; }
|
||||
public ServerVehicle Vehicle { get; set; }
|
||||
public virtual ServerVehicle Vehicle { get; set; }
|
||||
|
||||
public int Slot { get; set; }
|
||||
public int ModId { get; set; }
|
||||
|
||||
1145
ReallifeGamemode.Server/Migrations/20190513104140_Jobs.Designer.cs
generated
Normal file
1145
ReallifeGamemode.Server/Migrations/20190513104140_Jobs.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
90
ReallifeGamemode.Server/Migrations/20190513104140_Jobs.cs
Normal file
90
ReallifeGamemode.Server/Migrations/20190513104140_Jobs.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace ReallifeGamemode.Migrations
|
||||
{
|
||||
public partial class Jobs : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "JobId",
|
||||
table: "Users",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "JobId",
|
||||
table: "ServerVehicles",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Jobs",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
Name = table.Column<string>(nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Jobs", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Users_JobId",
|
||||
table: "Users",
|
||||
column: "JobId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ServerVehicles_JobId",
|
||||
table: "ServerVehicles",
|
||||
column: "JobId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ServerVehicles_Jobs_JobId",
|
||||
table: "ServerVehicles",
|
||||
column: "JobId",
|
||||
principalTable: "Jobs",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Users_Jobs_JobId",
|
||||
table: "Users",
|
||||
column: "JobId",
|
||||
principalTable: "Jobs",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ServerVehicles_Jobs_JobId",
|
||||
table: "ServerVehicles");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Users_Jobs_JobId",
|
||||
table: "Users");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Jobs");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Users_JobId",
|
||||
table: "Users");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_ServerVehicles_JobId",
|
||||
table: "ServerVehicles");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "JobId",
|
||||
table: "Users");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "JobId",
|
||||
table: "ServerVehicles");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -420,6 +420,18 @@ namespace ReallifeGamemode.Migrations
|
||||
b.ToTable("Interiors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Server.Entities.Job", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("Name");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Jobs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Server.Entities.Logs.BankAccountTransactionHistory", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@@ -778,6 +790,8 @@ namespace ReallifeGamemode.Migrations
|
||||
|
||||
b.Property<int>("Handmoney");
|
||||
|
||||
b.Property<int?>("JobId");
|
||||
|
||||
b.Property<int>("LogUserId");
|
||||
|
||||
b.Property<string>("Name")
|
||||
@@ -813,6 +827,8 @@ namespace ReallifeGamemode.Migrations
|
||||
|
||||
b.HasIndex("GroupId");
|
||||
|
||||
b.HasIndex("JobId");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
@@ -915,6 +931,17 @@ namespace ReallifeGamemode.Migrations
|
||||
b.HasDiscriminator().HasValue("GroupVehicle");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Server.Entities.JobVehicle", b =>
|
||||
{
|
||||
b.HasBaseType("ReallifeGamemode.Server.Entities.ServerVehicle");
|
||||
|
||||
b.Property<int?>("JobId");
|
||||
|
||||
b.HasIndex("JobId");
|
||||
|
||||
b.HasDiscriminator().HasValue("JobVehicle");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Server.Entities.Saves.SavedVehicle", b =>
|
||||
{
|
||||
b.HasBaseType("ReallifeGamemode.Server.Entities.ServerVehicle");
|
||||
@@ -1052,6 +1079,10 @@ namespace ReallifeGamemode.Migrations
|
||||
b.HasOne("ReallifeGamemode.Server.Entities.Group", "Group")
|
||||
.WithMany()
|
||||
.HasForeignKey("GroupId");
|
||||
|
||||
b.HasOne("ReallifeGamemode.Server.Entities.Job", "Job")
|
||||
.WithMany()
|
||||
.HasForeignKey("JobId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Server.Entities.UserBankAccount", b =>
|
||||
@@ -1092,6 +1123,13 @@ namespace ReallifeGamemode.Migrations
|
||||
.HasForeignKey("GroupId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Server.Entities.JobVehicle", b =>
|
||||
{
|
||||
b.HasOne("ReallifeGamemode.Server.Entities.Job", "Job")
|
||||
.WithMany()
|
||||
.HasForeignKey("JobId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Server.Entities.UserVehicle", b =>
|
||||
{
|
||||
b.HasOne("ReallifeGamemode.Server.Entities.User", "User")
|
||||
|
||||
@@ -12,8 +12,9 @@ namespace ReallifeGamemode.Server.Models
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
optionsBuilder.UseMySql("Host=localhost;Port=3306;Database=gtav-devdb;Username=gtav-dev;Password=Test123");
|
||||
optionsBuilder
|
||||
.UseMySql("Host=localhost;Port=3306;Database=gtav-devdb;Username=gtav-dev;Password=Test123")
|
||||
.UseLazyLoadingProxies();
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
@@ -99,5 +100,9 @@ namespace ReallifeGamemode.Server.Models
|
||||
public DbSet<Entities.Group> Groups { get; set; }
|
||||
public DbSet<Entities.GroupBankAccount> GroupBankAccounts { get; set; }
|
||||
public DbSet<Entities.GroupVehicle> GroupVehicles { get; set; }
|
||||
|
||||
// Jobs
|
||||
public DbSet<Entities.Job> Jobs { get; set; }
|
||||
public DbSet<Entities.JobVehicle> JobVehicles { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,12 +15,13 @@
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.0">
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="2.2.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.1.4" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.2" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(ConfigurationName)' != 'ServerBuild'">
|
||||
|
||||
Reference in New Issue
Block a user