исправление связи

This commit is contained in:
sardq 2024-05-17 15:20:57 +04:00
parent e22020f8ab
commit 7e61baddbf
5 changed files with 60 additions and 21 deletions

View File

@ -12,7 +12,7 @@ using PlumbingRepairDatabaseImplement;
namespace PlumbingRepairDatabaseImplement.Migrations
{
[DbContext(typeof(PlumbingRepairDatabase))]
[Migration("20240515153909_InitCreate")]
[Migration("20240517111715_InitCreate")]
partial class InitCreate
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -127,6 +127,8 @@ namespace PlumbingRepairDatabaseImplement.Migrations
b.HasKey("MessageId");
b.HasIndex("ClientId");
b.ToTable("Messages");
});
@ -272,6 +274,15 @@ namespace PlumbingRepairDatabaseImplement.Migrations
b.ToTable("WorkComponents");
});
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.MessageInfo", b =>
{
b.HasOne("PlumbingRepairDatabaseImplement.Models.Client", "Client")
.WithMany("Messages")
.HasForeignKey("ClientId");
b.Navigation("Client");
});
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Order", b =>
{
b.HasOne("PlumbingRepairDatabaseImplement.Models.Client", "Client")
@ -337,6 +348,8 @@ namespace PlumbingRepairDatabaseImplement.Migrations
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Client", b =>
{
b.Navigation("Messages");
b.Navigation("Orders");
});

View File

@ -54,24 +54,6 @@ namespace PlumbingRepairDatabaseImplement.Migrations
table.PrimaryKey("PK_Implementers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Messages",
columns: table => new
{
MessageId = table.Column<string>(type: "nvarchar(450)", nullable: false),
ClientId = table.Column<int>(type: "int", nullable: true),
SenderName = table.Column<string>(type: "nvarchar(max)", nullable: false),
DateDelivery = table.Column<DateTime>(type: "datetime2", nullable: false),
Subject = table.Column<string>(type: "nvarchar(max)", nullable: false),
Body = table.Column<string>(type: "nvarchar(max)", nullable: false),
IsRead = table.Column<bool>(type: "bit", nullable: false),
ReplyText = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Messages", x => x.MessageId);
});
migrationBuilder.CreateTable(
name: "Shops",
columns: table => new
@ -102,6 +84,29 @@ namespace PlumbingRepairDatabaseImplement.Migrations
table.PrimaryKey("PK_Works", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Messages",
columns: table => new
{
MessageId = table.Column<string>(type: "nvarchar(450)", nullable: false),
ClientId = table.Column<int>(type: "int", nullable: true),
SenderName = table.Column<string>(type: "nvarchar(max)", nullable: false),
DateDelivery = table.Column<DateTime>(type: "datetime2", nullable: false),
Subject = table.Column<string>(type: "nvarchar(max)", nullable: false),
Body = table.Column<string>(type: "nvarchar(max)", nullable: false),
IsRead = table.Column<bool>(type: "bit", nullable: false),
ReplyText = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Messages", x => x.MessageId);
table.ForeignKey(
name: "FK_Messages_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Orders",
columns: table => new
@ -193,6 +198,11 @@ namespace PlumbingRepairDatabaseImplement.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Messages_ClientId",
table: "Messages",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_Orders_ClientId",
table: "Orders",

View File

@ -125,6 +125,8 @@ namespace PlumbingRepairDatabaseImplement.Migrations
b.HasKey("MessageId");
b.HasIndex("ClientId");
b.ToTable("Messages");
});
@ -270,6 +272,15 @@ namespace PlumbingRepairDatabaseImplement.Migrations
b.ToTable("WorkComponents");
});
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.MessageInfo", b =>
{
b.HasOne("PlumbingRepairDatabaseImplement.Models.Client", "Client")
.WithMany("Messages")
.HasForeignKey("ClientId");
b.Navigation("Client");
});
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Order", b =>
{
b.HasOne("PlumbingRepairDatabaseImplement.Models.Client", "Client")
@ -335,6 +346,8 @@ namespace PlumbingRepairDatabaseImplement.Migrations
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Client", b =>
{
b.Navigation("Messages");
b.Navigation("Orders");
});

View File

@ -20,8 +20,9 @@ namespace PlumbingRepairDatabaseImplement.Models
[ForeignKey("ClientId")]
public virtual List<Order> Orders{ get; set; } = new();
public static Client? Create(ClientBindingModel model)
[ForeignKey("ClientId")]
public virtual List<MessageInfo> Messages { get; set; } = new();
public static Client? Create(ClientBindingModel model)
{
if (model == null)
{

View File

@ -23,6 +23,8 @@ namespace PlumbingRepairDatabaseImplement.Models
public bool IsRead { get; private set; } = false;
public string? ReplyText { get; private set; }
public virtual Client? Client { get; private set; }
public static MessageInfo? Create(MessageInfoBindingModel model)
{
if (model == null)