#224 removing redundant data

This commit is contained in:
Hamid Reza Mohammadi 2021-10-21 19:29:53 +03:30
parent 954e32ec84
commit 827fa3501b
6 changed files with 17 additions and 14 deletions

View File

@ -69,6 +69,11 @@
<input type="text" name="@($"pinorder-{poet.Id}")" id="@($"pinorder-{poet.Id}")" value="@poet.PinOrder" />
</td>
</tr>
<tr>
<td colspan="4">
@Html.Raw(poet.Description)
</td>
</tr>
}
<tr>
<td colspan="4">

View File

@ -10,7 +10,7 @@ using RMuseum.DbContext;
namespace RMuseum.Migrations
{
[DbContext(typeof(RMuseumDbContext))]
[Migration("20211021145514_GanjoorHalfCenturies")]
[Migration("20211021153153_GanjoorHalfCenturies")]
partial class GanjoorHalfCenturies
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -839,7 +839,7 @@ namespace RMuseum.Migrations
b.Property<int?>("GanjoorHalfCenturyId")
.HasColumnType("int");
b.Property<int>("PoetId")
b.Property<int?>("PoetId")
.HasColumnType("int");
b.Property<int>("PoetOrder")
@ -2735,9 +2735,7 @@ namespace RMuseum.Migrations
b.HasOne("RMuseum.Models.Ganjoor.GanjoorPoet", "Poet")
.WithMany()
.HasForeignKey("PoetId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.HasForeignKey("PoetId");
b.Navigation("Poet");
});

View File

@ -51,7 +51,7 @@ namespace RMuseum.Migrations
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PoetOrder = table.Column<int>(type: "int", nullable: false),
PoetId = table.Column<int>(type: "int", nullable: false),
PoetId = table.Column<int>(type: "int", nullable: true),
GanjoorHalfCenturyId = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
@ -68,7 +68,7 @@ namespace RMuseum.Migrations
column: x => x.PoetId,
principalTable: "GanjoorPoets",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(

View File

@ -837,7 +837,7 @@ namespace RMuseum.Migrations
b.Property<int?>("GanjoorHalfCenturyId")
.HasColumnType("int");
b.Property<int>("PoetId")
b.Property<int?>("PoetId")
.HasColumnType("int");
b.Property<int>("PoetOrder")
@ -2733,9 +2733,7 @@ namespace RMuseum.Migrations
b.HasOne("RMuseum.Models.Ganjoor.GanjoorPoet", "Poet")
.WithMany()
.HasForeignKey("PoetId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.HasForeignKey("PoetId");
b.Navigation("Poet");
});

View File

@ -18,11 +18,11 @@
/// <summary>
/// poet id
/// </summary>
public int PoetId { get; set; }
public int? PoetId { get; set; }
/// <summary>
/// poet
/// </summary>
public GanjoorPoet Poet { get; set; }
public virtual GanjoorPoet Poet { get; set; }
}
}

View File

@ -22,9 +22,11 @@ namespace RMuseum.Services.Implementation
{
try
{
var oldOnes = await _context.GanjoorHalfCenturies.Include(o => o.Poets)).ToArrayAsync();
await _context.Database.ExecuteSqlRawAsync("DELETE FROM GanjoorPeriodPoet");
var oldOnes = await _context.GanjoorHalfCenturies.ToArrayAsync();
_context.RemoveRange(oldOnes);
await _context.SaveChangesAsync();
var periods = new List<GanjoorHalfCentury>
{