Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WhereDynamicFilter #371

Closed
qiuhaohui163 opened this issue Jul 13, 2020 · 6 comments
Closed

WhereDynamicFilter #371

qiuhaohui163 opened this issue Jul 13, 2020 · 6 comments

Comments

@qiuhaohui163
Copy link

使用WhereDynamicFilter条件搜索, netcore 使用system.text.json
因为DynamicFilterInfo 的value 类型为object 故反序列化的时候value类型为jsonElement,
因此会报错
如下图:
image
除了改用AddNewtonsoftJson, 请问有什么其他解决办法继续使用system.text.json吗?

@2881099
Copy link
Collaborator

2881099 commented Jul 13, 2020

用的是哪个版本?

@2881099
Copy link
Collaborator

2881099 commented Jul 13, 2020

前面传过来的 json 是什么内容,发出来我试试

@2881099
Copy link
Collaborator

2881099 commented Jul 13, 2020

我测试了,system.text.json 得到的确实是 JsonElement,你应该用的是 1.5 版本,1.6 版本有过更新解决了该问题。

更新日志:https://github.com/dotnetcore/FreeSql/wiki/%E6%9B%B4%E6%96%B0%E6%97%A5%E5%BF%97

建议持续关注更新日志。

@qiuhaohui163
Copy link
Author

qiuhaohui163 commented Jul 13, 2020

大佬, 我改了一下版本好像还是不行. 还需要哪里设置吗?
原来用的是1.7.0-preview 0705
版本号 从1.6的第一个preview包括正式版本, 到1.7最新的preview都试了

 var config = new JsonSerializerOptions()
        {
            PropertyNamingPolicy = null,
            AllowTrailingCommas = true,
            IgnoreNullValues = true,
            Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
            Converters = { new JsonStringEnumConverter() }
        };

        DynamicFilterInfo dyfilter = JsonSerializer.Deserialize<DynamicFilterInfo>(@"
            {
              ""Logic"" : ""And"",
              ""Filters"" :
              [
                {
                  ""Field"" : ""Name"",
                  ""Operator"" : ""Contains"",
                  ""Value"" : ""test""
                },
                {
                  ""Field"" : ""EName"",
                  ""Operator"" : ""Eq"",
                  ""Value"" : ""test""
                }
              ]
            }
            ", config);
       
        var res = await _sql.Select<XXXX>().WhereDynamicFilter(dyfilter).ToListAsync();

@2881099
Copy link
Collaborator

2881099 commented Jul 13, 2020

好的,测到了漏网之鱼,等我发个 preview0713

@2881099
Copy link
Collaborator

2881099 commented Jul 13, 2020

1.7.0-preview0713 更新到这个版本可以解决你说的问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants