Files
prefab-page-detail/Prefab/Data/Extensions.cs
2025-10-27 17:39:18 -04:00

27 lines
841 B
C#

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));
});
}
}