NickStrupat/EntityFramework.Triggers

GlobalInserted or GlobalUpdate not work

firmin-oke opened this issue · 1 comments

Hi,
i'm trying to use your library but i don't understant why GlobalInserted or GlobalUpdate does'nt work, events is not fired when SaveChanges is called

Hmm it's working on my end... could you try this?

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="EntityFrameworkCore.Triggers" Version="1.2.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.0" />
  </ItemGroup>

</Project>
using EntityFrameworkCore.Triggers;
using Microsoft.EntityFrameworkCore;
using System;

namespace EntityFramework.Triggers.Issue_51
{
	class Program
	{
		static void Main(string[] args)
		{
			using var context = new Context();
			context.Add(new Entity());
			context.SaveChanges();
		}
	}

	public class Context : DbContextWithTriggers
	{
		public DbSet<Entity> Entities { get; set; }

		protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
		{
			if (!optionsBuilder.IsConfigured)
				optionsBuilder.UseInMemoryDatabase("mem");
		}
	}

	public class Entity
	{
		public Int64 Id { get; private set; }

		static Entity()
		{
			Triggers<Entity>.Inserting += _ => Console.WriteLine("Inserting");
			Triggers<Entity>.GlobalInserting.Add(_ => Console.WriteLine("GlobalInserting"));
		}
	}
}