提交 5962ad15 编写于 作者: S Shay Rojansky

Fix type mappings for JSON containment functions

Fixes #1139
上级 5b356c72
......@@ -65,13 +65,13 @@ public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadO
{
nameof(NpgsqlJsonDbFunctionsExtensions.JsonContains) => new SqlCustomBinaryExpression(
_sqlExpressionFactory.ApplyTypeMapping(args[0], _jsonbTypeMapping),
_sqlExpressionFactory.ApplyDefaultTypeMapping(args[1]),
_sqlExpressionFactory.ApplyTypeMapping(args[1], _jsonbTypeMapping),
"@>",
typeof(bool),
_boolTypeMapping),
nameof(NpgsqlJsonDbFunctionsExtensions.JsonContained) => new SqlCustomBinaryExpression(
_sqlExpressionFactory.ApplyDefaultTypeMapping(args[0]),
_sqlExpressionFactory.ApplyTypeMapping(args[0], _jsonbTypeMapping),
_sqlExpressionFactory.ApplyTypeMapping(args[1], _jsonbTypeMapping),
"<@",
typeof(bool),
......
......@@ -347,7 +347,7 @@ public void JsonContains_with_json_element()
}
[Fact]
public void JsonContains_with_string()
public void JsonContains_with_string_literal()
{
using var ctx = CreateContext();
var count = ctx.JsonbEntities.Count(e =>
......@@ -360,6 +360,24 @@ public void JsonContains_with_string()
WHERE (j.""Customer"" @> '{""Name"": ""Joe"", ""Age"": 25}')");
}
[Fact]
public void JsonContains_with_string_parameter()
{
using var ctx = CreateContext();
var someJson = @"{""Name"": ""Joe"", ""Age"": 25}";
var count = ctx.JsonbEntities.Count(e =>
EF.Functions.JsonContains(e.Customer, someJson));
Assert.Equal(1, count);
AssertSql(
@"@__someJson_1='{""Name"": ""Joe""
""Age"": 25}' (DbType = Object)
SELECT COUNT(*)::INT
FROM ""JsonbEntities"" AS j
WHERE (j.""Customer"" @> @__someJson_1)");
}
[Fact]
public void JsonContained_with_json_element()
{
......@@ -379,7 +397,7 @@ public void JsonContained_with_json_element()
}
[Fact]
public void JsonContained_with_string()
public void JsonContained_with_string_literal()
{
using var ctx = CreateContext();
var count = ctx.JsonbEntities.Count(e =>
......@@ -392,6 +410,24 @@ public void JsonContained_with_string()
WHERE ('{""Name"": ""Joe"", ""Age"": 25}' <@ j.""Customer"")");
}
[Fact]
public void JsonContained_with_string_parameter()
{
using var ctx = CreateContext();
var someJson = @"{""Name"": ""Joe"", ""Age"": 25}";
var count = ctx.JsonbEntities.Count(e =>
EF.Functions.JsonContained(someJson, e.Customer));
Assert.Equal(1, count);
AssertSql(
@"@__someJson_1='{""Name"": ""Joe""
""Age"": 25}' (DbType = Object)
SELECT COUNT(*)::INT
FROM ""JsonbEntities"" AS j
WHERE (@__someJson_1 <@ j.""Customer"")");
}
[Fact]
public void JsonExists()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册