win7user10 / Laraue.EfCoreTriggers

Library to write triggers in C# with EF.Core
MIT License
111 stars 20 forks source link

Support for mapped JSON types in Postgres #99

Open bhavishyachandra opened 7 months ago

bhavishyachandra commented 7 months ago

Looks like the json properties are mapped as navigation properties instead of scalar properties, despite being in the same table. Would be great if the GetColumnName() could also look at these navigation properties for determining the column name in such circurmstances.

My temporary solution for now was to make the column a string as I don't plan on querying it for now. I could see how this can get inconvenient as more people start using the native json column implementation in EF Core. I tried to implement a custom DbSchemaRetriever but was running into some strange errors during the design time. It'd also be great if we could add an inbuilt jsonb comparer for nested properties to check for equality on json objects in postgres. Thanks for creating this wonderful package, everything just works as expected.

`public class JsonbMethodCallConverter : IMethodCallVisitor { private readonly IExpressionVisitorFactory _visitorFactory;

public JsonbMethodCallConverter(IExpressionVisitorFactory visitorFactory)
{
    _visitorFactory = visitorFactory;
}

public bool IsApplicable(MethodCallExpression expression)
{
    return expression.Method.ReflectedType == typeof(JsonbEfCoreDesignTriggerExtensions) && expression.Method.Name == "ToJsonbNoOpEfComparer";
}

public SqlBuilder Visit(MethodCallExpression expression, VisitedMembers visitedMembers)
{
    var sqlBuilder = _visitorFactory.Visit(expression.Arguments.First(), visitedMembers);
    return sqlBuilder.Append("::jsonb");
}

} `