Restore DeleteOrphansTiming value of ChangeTracker.

pull/3665/head
maliming 5 years ago
parent 03386cce3d
commit 03abe372ee

@ -155,7 +155,6 @@ namespace Volo.Abp.EntityFrameworkCore
}
ChangeTracker.CascadeDeleteTiming = CascadeTiming.OnSaveChanges;
ChangeTracker.DeleteOrphansTiming = CascadeTiming.OnSaveChanges;
ChangeTracker.Tracked += ChangeTracker_Tracked;
}

@ -1,4 +1,4 @@
using System;
using System;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
@ -38,6 +38,11 @@ namespace Volo.Abp.EntityFrameworkCore
{
opt.DefaultWithDetailsFunc = q => q.Include(p => p.Phones);
});
options.Entity<Author>(opt =>
{
opt.DefaultWithDetailsFunc = q => q.Include(p => p.Books);
});
});
var sqliteConnection = CreateDatabaseAndGetConnection();

@ -1,9 +1,49 @@
using Volo.Abp.TestApp.Testing;
using System;
using System.Linq;
using System.Threading.Tasks;
using Shouldly;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.TestApp;
using Volo.Abp.TestApp.Domain;
using Volo.Abp.TestApp.Testing;
using Volo.Abp.Uow;
using Xunit;
namespace Volo.Abp.EntityFrameworkCore.DataFiltering
{
/// <summary>
/// This is just to test the cascade delete behavior of EF Core's navigation properties.
/// Soft delete is usually only used in the aggregate root entity instead <see cref="Book" />.
/// </summary>
public class SoftDelete_Tests : SoftDelete_Tests<AbpEntityFrameworkCoreTestModule>
{
[Fact]
public async Task Navigation_Properties_Cascade_Delete_Test()
{
var authorRepository = GetRequiredService<IRepository<Author, Guid>>();
var authorId = Guid.NewGuid();
var author = new Author(authorId, "tom");
author.Books.Add(new Book(authorId, Guid.NewGuid(), "asp net core"));
author.Books.Add(new Book(authorId, Guid.NewGuid(),"c#"));
await authorRepository.InsertAsync(author);
await WithUnitOfWorkAsync(async () =>
{
var author = await authorRepository.GetAsync(authorId);
author.Books.ShouldNotBeEmpty();
author.Books.Count.ShouldBe(2);
author.Books.Clear();
await authorRepository.UpdateAsync(author);
});
using (DataFilter.Disable<ISoftDelete>())
{
author = await authorRepository.GetAsync(authorId);
author.Books.ShouldNotBeEmpty();
author.Books.ShouldAllBe(x => x.IsDeleted);
}
}
}
}

@ -1,4 +1,4 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.TestApp.SecondContext;
using Volo.Abp.EntityFrameworkCore.TestApp.ThirdDbContext;
using Volo.Abp.TestApp.Domain;
@ -16,7 +16,9 @@ namespace Volo.Abp.EntityFrameworkCore
public DbSet<BookInSecondDbContext> Books { get; set; }
public DbSet<EntityWithIntPk> EntityWithIntPks { get; set; }
public DbSet<Author> Author { get; set; }
public TestMigrationsDbContext(DbContextOptions<TestMigrationsDbContext> options)
: base(options)
{

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.TestApp.Domain
{
public class Author : AggregateRoot<Guid>
{
public string Name { get; set; }
public ICollection<Book> Books { get; set; }
private Author()
{
}
public Author(Guid id, string name)
: base(id)
{
Name = name;
Books = new List<Book>();
}
}
}

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.TestApp.Domain
{
public class Book : Entity<Guid>, ISoftDelete
{
public Guid AuthorId { get; set; }
public string Title { get; set; }
private Book()
{
}
public Book(Guid authorId, Guid id, string title)
{
Id = id;
AuthorId = authorId;
Title = title;
}
public bool IsDeleted { get; set; }
}
}

@ -17,6 +17,8 @@ namespace Volo.Abp.TestApp.EntityFrameworkCore
public DbSet<EntityWithIntPk> EntityWithIntPks { get; set; }
public DbSet<Author> Author { get; set; }
public TestAppDbContext(DbContextOptions<TestAppDbContext> options)
: base(options)
{

Loading…
Cancel
Save