Skip to content

Commit

Permalink
Improved database concurrency checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix-CodingClimber committed Jan 11, 2024
1 parent 5779703 commit 698238e
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 212 deletions.

This file was deleted.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#nullable disable

namespace DotNetElements.Migrations
namespace DotNetElements.CrudExample.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
Expand All @@ -17,6 +17,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
{
Id = table.Column<Guid>(type: "TEXT", nullable: false),
Title = table.Column<string>(type: "nvarchar(256)", nullable: false),
Version = table.Column<Guid>(type: "TEXT", nullable: false),
CreatorId = table.Column<Guid>(type: "TEXT", nullable: false),
CreationTime = table.Column<DateTimeOffset>(type: "TEXT", nullable: false),
LastModifierId = table.Column<Guid>(type: "TEXT", nullable: true),
Expand All @@ -33,6 +34,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
{
Id = table.Column<Guid>(type: "TEXT", nullable: false),
Label = table.Column<string>(type: "nvarchar(256)", nullable: false),
Version = table.Column<Guid>(type: "TEXT", nullable: false),
CreatorId = table.Column<Guid>(type: "TEXT", nullable: false),
CreationTime = table.Column<DateTimeOffset>(type: "TEXT", nullable: false),
LastModifierId = table.Column<Guid>(type: "TEXT", nullable: true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#nullable disable

namespace DotNetElements.Migrations
namespace DotNetElements.CrudExample.Migrations
{
[DbContext(typeof(AppDbContext))]
partial class AppDbContextModelSnapshot : ModelSnapshot
Expand All @@ -17,7 +17,22 @@ protected override void BuildModel(ModelBuilder modelBuilder)
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.0");

modelBuilder.Entity("BlazorCrud.Modules.BlogPostModule.BlogPost", b =>
modelBuilder.Entity("BlogPostTag", b =>
{
b.Property<Guid>("BlogPostsId")
.HasColumnType("TEXT");

b.Property<Guid>("TagsId")
.HasColumnType("TEXT");

b.HasKey("BlogPostsId", "TagsId");

b.HasIndex("TagsId");

b.ToTable("BlogPostTag");
});

modelBuilder.Entity("DotNetElements.CrudExample.Modules.BlogPostModule.BlogPost", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
Expand Down Expand Up @@ -48,7 +63,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("BlogPosts");
});

modelBuilder.Entity("BlazorCrud.Modules.TagModule.Tag", b =>
modelBuilder.Entity("DotNetElements.CrudExample.Modules.TagModule.Tag", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
Expand Down Expand Up @@ -81,28 +96,13 @@ protected override void BuildModel(ModelBuilder modelBuilder)

modelBuilder.Entity("BlogPostTag", b =>
{
b.Property<Guid>("BlogPostsId")
.HasColumnType("TEXT");

b.Property<Guid>("TagsId")
.HasColumnType("TEXT");

b.HasKey("BlogPostsId", "TagsId");

b.HasIndex("TagsId");

b.ToTable("BlogPostTag");
});

modelBuilder.Entity("BlogPostTag", b =>
{
b.HasOne("BlazorCrud.Modules.BlogPostModule.BlogPost", null)
b.HasOne("DotNetElements.CrudExample.Modules.BlogPostModule.BlogPost", null)
.WithMany()
.HasForeignKey("BlogPostsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

b.HasOne("BlazorCrud.Modules.TagModule.Tag", null)
b.HasOne("DotNetElements.CrudExample.Modules.TagModule.Tag", null)
.WithMany()
.HasForeignKey("TagsId")
.OnDelete(DeleteBehavior.Cascade)
Expand Down
3 changes: 2 additions & 1 deletion samples/DotNetElements.CrudExample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using DotNetElements.Datahandling;
using MudBlazor.Services;
using DotNetElements.CrudExample.Components;
using DotNetElements.CrudExample.Modules.BlogPostModule;

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -18,7 +19,7 @@
builder.Services.AddDatabaseMigrationService<AppDbContext>();
builder.AddSettings<AppDatabaseSettings>();

builder.Services.RegisterModules();
builder.Services.RegisterModules(typeof(BlogPostModule).Assembly);

var app = builder.Build();

Expand Down
Binary file modified samples/DotNetElements.CrudExample/TestDb.db
Binary file not shown.
Binary file modified samples/DotNetElements.CrudExample/TestDb.db-shm
Binary file not shown.
Binary file modified samples/DotNetElements.CrudExample/TestDb.db-wal
Binary file not shown.
9 changes: 0 additions & 9 deletions src/DotNetElements.Core/Core/EntityBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.ComponentModel;
using System.Diagnostics.Eventing.Reader;

namespace DotNetElements.Core;

Expand Down Expand Up @@ -59,14 +58,6 @@ public interface IDeletionAuditedEntity : IHasDeletionTime
void Delete(Guid deleterId, DateTimeOffset deletionTime);
}

/// <summary>
/// To make use of Ef Cores concurrency check, add a <see cref="ConcurrencyCheckAttribute"/> to the property.
/// </summary>
public interface IHasVersion
{
public Guid Version { get; set; }
}

public interface IUpdatable<TFrom>
{
void Update(TFrom from, IAttachRelatedEntity attachRelatedEntity);
Expand Down
Loading

0 comments on commit 698238e

Please sign in to comment.