Move concurrency stamp convention to AbpDbContext.

pull/81/head
Halil İbrahim Kalkan 9 years ago
parent b878f78912
commit 5c8a5db75e

@ -18,12 +18,12 @@ namespace AbpDesk.EntityFrameworkCore
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//TODO: Use different classes to map each entity type?
base.OnModelCreating(modelBuilder);
//Use different classes to map each entity type?
modelBuilder.Entity<Ticket>(builder =>
{
builder.ToTable("DskTickets");
builder.Property(t => t.ConcurrencyStamp).IsConcurrencyToken();
});
}
}

@ -1,6 +1,10 @@
using System.Threading;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Uow;
namespace Volo.Abp.EntityFrameworkCore
@ -18,7 +22,10 @@ namespace Volo.Abp.EntityFrameworkCore
{
base.OnModelCreating(modelBuilder);
//TODO: Automatically configure ConcurrencyStamp
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
{
ConfigureConcurrencyStamp(entityType);
}
}
public override int SaveChanges(bool acceptAllChangesOnSuccess)
@ -44,5 +51,18 @@ namespace Volo.Abp.EntityFrameworkCore
throw new AbpDbConcurrencyException(ex.Message, ex);
}
}
protected virtual void ConfigureConcurrencyStamp(IMutableEntityType entityType)
{
if (!typeof(IHasConcurrencyStamp).GetTypeInfo().IsAssignableFrom(entityType.ClrType))
{
return;
}
entityType
.GetProperties()
.First(p => p.Name == nameof(IHasConcurrencyStamp.ConcurrencyStamp))
.IsConcurrencyToken = true;
}
}
}

@ -64,14 +64,11 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
base.OnModelCreating(builder);
//TODO: Set Default Values for properties
//TODO: Split configuration to dedicated classes.
builder.Entity<IdentityUser>(b =>
{
b.ToTable("IdentityUsers");
b.Property(u => u.ConcurrencyStamp).IsConcurrencyToken();
b.Property(u => u.UserName).HasMaxLength(256);
b.Property(u => u.NormalizedUserName).HasMaxLength(256);
b.Property(u => u.Email).HasMaxLength(256);

Loading…
Cancel
Save