Expression表达式的远程传输中序列化

测试orm发现a => a.userName == userN和a => a.userName == “张三”居然效果不一样,string类型的userN被序列化表达式为+<>c__DisplayClass5_0

硬编码可以过,传输的变量就不行,最终用最笨的方法组装语句System.Linq.Dynamic.DynamicExpression.ParseLambda<Users, bool>("userName=@0", userN)

还需要nuget下载Dynamic Expression API

网址参考:https://blog.csdn.net/weixin_30835649/article/details/95826580

另:

http://cn.voidcc.com/question/p-oxxlquww-xt.html

给出解决方案是用type.IsDefined (typeof (CompilerGeneratedAttribute), false)

实测未起效,还需要其他思路,如更换dapper用orm

 

posted @ 2022-05-16 01:50  SHW03  阅读(48)  评论(0编辑  收藏  举报