Init
This commit is contained in:
26
Prefab/Data/Extensions.cs
Normal file
26
Prefab/Data/Extensions.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Prefab.Domain.Common;
|
||||
|
||||
namespace Prefab.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="ModelBuilder"/> when configuring the database model.
|
||||
/// </summary>
|
||||
public static class ModelBuilderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Ignores the domain event collection for all entities implementing <see cref="IHasDomainEvents"/>.
|
||||
/// </summary>
|
||||
/// <param name="builder">The model builder to configure.</param>
|
||||
public static void IgnoreDomainEvents(this ModelBuilder builder)
|
||||
{
|
||||
builder.Model
|
||||
.GetEntityTypes()
|
||||
.Where(e => typeof(IHasDomainEvents).IsAssignableFrom(e.ClrType))
|
||||
.ToList()
|
||||
.ForEach(e =>
|
||||
{
|
||||
builder.Entity(e.ClrType).Ignore(nameof(IHasDomainEvents.Events));
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user