Laraue.EfCoreTriggers icon indicating copy to clipboard operation
Laraue.EfCoreTriggers copied to clipboard

Null coalesce not working in SQL Server

Open JarRami opened this issue 2 years ago • 0 comments

If I have a table like

public class NullableHolder {
	[Key]
	public int ID { get; set; }
	public int? Value { get; set; }
}

And I try to create an AfterInsert trigger with a Condition like

modelBuilder.Entity<NullableHolder>()
	.AfterInsert(trigger => trigger
		.Action(action => action
			.Condition(nh => (nh.Value ?? -1) != 7)
		)
	);

or a similar Update trigger with a condition comparing values, then after doing an Add-Migration I get an error

System.NotSupportedException: Unknown sign of Coalesce at Laraue.EfCoreTriggers.Common.Services.Impl.SqlGenerator.GetOperand(Expression expression) at Laraue.EfCoreTriggers.SqlServer.SqlServerSqlGenerator.GetOperand(Expression expression) ...

This is with the Sql Server triggers package. Is the null coalescing something that could be supported and turned into something like ISNULL(VALUE, -1) <> 7 (or equivalent in whatever SQL product this is run against)?

Unfortunately, I'm not able to run .NET6 so this behaviour is seen against library version 5.3.6.

JarRami avatar Oct 12 '22 04:10 JarRami