最近测试组提了一个bug,说是某个报表点击查询报错,查看错误log,错误信息如下。

类型“Ticket.Data.SqlFuns”上指定的方法“Boolean ContainsAll(System.String, System.String)”无法转换为 LINQ to Entities 存储表达式。

定位到错误行,发现是一个自定义的SQLCLR函数,如下代码。

为什么使用CLR函数ContainsAll报错

理论上CLR函数可以用在lambda表达式中,但是为什么现在突然就不行了呢?

依据错误提示,首先想到的是,函数ContainsAll已经不在edmx文件中了,查看edmx文件的历史记录,对比发现,果然CLR函数被删除了,如下图。

解决方案:

用新的'数据库生成工作流'文件,重新生成,结果edmx就会包含那些CLR函数了。

附数据库生成工作流文件:

<Activity mc:Ignorable="sap sap2010 sads" x:Class="GenerateDatabaseScriptWorkflow"
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mdedda="clr-namespace:Microsoft.Data.Entity.Design.DatabaseGeneration.Activities;assembly=Microsoft.Data.Entity.Design.DatabaseGeneration"
xmlns:mdedda1="clr-namespace:Microsoft.Data.Entity.Design.DatabaseGeneration.Activities;assembly=Microsoft.Data.Entity.Design"
xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
xmlns:sap2010="http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation"
xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"
xmlns:sco="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib"
xmlns:sdme="clr-namespace:System.Data.Metadata.Edm;assembly=System.Data.Entity"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<x:Members>
<x:Property Name="Csdl" Type="InArgument(sdme:EdmItemCollection)" />
<x:Property Name="ExistingSsdl" Type="InArgument(x:String)" />
<x:Property Name="ExistingMsl" Type="InArgument(x:String)" />
<x:Property Name="Ssdl" Type="OutArgument(x:String)" />
<x:Property Name="Msl" Type="OutArgument(x:String)" />
<x:Property Name="Ddl" Type="OutArgument(x:String)" />
</x:Members>
<sap2010:WorkflowViewState.IdRef>GenerateDatabaseScriptWorkflow_1</sap2010:WorkflowViewState.IdRef>
<TextExpression.NamespacesForImplementation>
<sco:Collection x:TypeArguments="x:String">
<x:String>System.Activities</x:String>
<x:String>System</x:String>
<x:String>Microsoft.VisualBasic</x:String>
<x:String>System.Xml.Linq</x:String>
<x:String>System.Xml</x:String>
<x:String>System.Xml.Serialization</x:String>
</sco:Collection>
</TextExpression.NamespacesForImplementation>
<TextExpression.ReferencesForImplementation>
<sco:Collection x:TypeArguments="AssemblyReference">
<AssemblyReference>System.Activities</AssemblyReference>
<AssemblyReference>mscorlib</AssemblyReference>
<AssemblyReference>System</AssemblyReference>
<AssemblyReference>System.Core</AssemblyReference>
<AssemblyReference>System.ComponentModel.Composition</AssemblyReference>
<AssemblyReference>System.ServiceModel</AssemblyReference>
<AssemblyReference>Microsoft.VisualBasic.Editor</AssemblyReference>
<AssemblyReference>Microsoft.VisualBasic.LanguageService</AssemblyReference>
<AssemblyReference>Microsoft.VisualBasic</AssemblyReference>
<AssemblyReference>Microsoft.VisualStudio.VisualBasic.LanguageService</AssemblyReference>
<AssemblyReference>System.Xml.Linq</AssemblyReference>
<AssemblyReference>System.Xml</AssemblyReference>
<AssemblyReference>System.Data</AssemblyReference>
<AssemblyReference>System.Runtime.Serialization</AssemblyReference>
</sco:Collection>
</TextExpression.ReferencesForImplementation>
<Sequence sap2010:WorkflowViewState.IdRef="Sequence_1">
<mdedda:CsdlToSsdlAndMslActivity CsdlInput="[Csdl]" sap2010:WorkflowViewState.IdRef="CsdlToSsdlAndMslActivity_1" MslOutput="[Msl]" MslOutputGeneratorType="Microsoft.Data.Entity.Design.DatabaseGeneration.OutputGenerators.CsdlToMsl, Microsoft.Data.Entity.Design.DatabaseGeneration" OutputGeneratorType="Microsoft.Data.Entity.Design.DatabaseGeneration.OutputGenerators.CsdlToSsdl, Microsoft.Data.Entity.Design.DatabaseGeneration" SsdlOutput="[Ssdl]" />
<Assign sap2010:WorkflowViewState.IdRef="Assign_2">
<Assign.To>
<OutArgument x:TypeArguments="x:String">[Ssdl]</OutArgument>
</Assign.To>
<Assign.Value>
<InArgument x:TypeArguments="x:String" xml:space="preserve">[Ssdl.Replace("&lt;/Schema&gt;", " &lt;Function Name=""ContainsAll"" ReturnType=""bit"" Aggregate=""false"" BuiltIn=""false"" NiladicFunction=""false"" IsComposable=""true"" ParameterTypeSemantics=""AllowImplicitConversion"" Schema=""dbo""&gt;" &amp; vbNewLine &amp; " &lt;Parameter Name=""input"" Type=""nvarchar(max)"" Mode=""In"" /&gt;" &amp; vbNewLine &amp; " &lt;Parameter Name=""search"" Type=""nvarchar"" Mode=""In"" /&gt;" &amp; vbNewLine &amp; " &lt;/Function&gt;" &amp; vbNewLine &amp; " &lt;Function Name=""ContainsAny"" ReturnType=""bit"" Aggregate=""false"" BuiltIn=""false"" NiladicFunction=""false"" IsComposable=""true"" ParameterTypeSemantics=""AllowImplicitConversion"" Schema=""dbo""&gt;" &amp; vbNewLine &amp; " &lt;Parameter Name=""input"" Type=""nvarchar(max)"" Mode=""In"" /&gt;" &amp; vbNewLine &amp; " &lt;Parameter Name=""search"" Type=""nvarchar"" Mode=""In"" /&gt;" &amp; vbNewLine &amp; " &lt;/Function&gt;" &amp; vbNewLine &amp; " &lt;Function Name=""ContainsOne"" ReturnType=""bit"" Aggregate=""false"" BuiltIn=""false"" NiladicFunction=""false"" IsComposable=""true"" ParameterTypeSemantics=""AllowImplicitConversion"" Schema=""dbo""&gt;" &amp; vbNewLine &amp; " &lt;Parameter Name=""input"" Type=""nvarchar(max)"" Mode=""In"" /&gt;" &amp; vbNewLine &amp; " &lt;Parameter Name=""search"" Type=""nvarchar"" Mode=""In"" /&gt;" &amp; vbNewLine &amp; " &lt;/Function&gt;" &amp; vbNewLine &amp; " &lt;Function Name=""GetDateTimeString"" ReturnType=""nvarchar"" Aggregate=""false"" BuiltIn=""false"" NiladicFunction=""false"" IsComposable=""true"" ParameterTypeSemantics=""AllowImplicitConversion"" Schema=""dbo""&gt;" &amp; vbNewLine &amp; " &lt;Parameter Name=""input"" Type=""datetime"" Mode=""In"" /&gt;" &amp; vbNewLine &amp; " &lt;Parameter Name=""format"" Type=""nvarchar"" Mode=""In"" /&gt;" &amp; vbNewLine &amp; " &lt;/Function&gt;" &amp; vbNewLine &amp; " &lt;Function Name=""RegexIsMatch"" ReturnType=""bit"" Aggregate=""false"" BuiltIn=""false"" NiladicFunction=""false"" IsComposable=""true"" ParameterTypeSemantics=""AllowImplicitConversion"" Schema=""dbo""&gt;" &amp; vbNewLine &amp; " &lt;Parameter Name=""input"" Type=""nvarchar(max)"" Mode=""In"" /&gt;" &amp; vbNewLine &amp; " &lt;Parameter Name=""pattern"" Type=""nvarchar"" Mode=""In"" /&gt;" &amp; vbNewLine &amp; " &lt;Parameter Name=""isIgnoreCase"" Type=""bit"" Mode=""In"" /&gt;" &amp; vbNewLine &amp; " &lt;/Function&gt;" &amp; vbNewLine &amp; " &lt;Function Name=""RegexMatch"" ReturnType=""nvarchar"" Aggregate=""false"" BuiltIn=""false"" NiladicFunction=""false"" IsComposable=""true"" ParameterTypeSemantics=""AllowImplicitConversion"" Schema=""dbo""&gt;" &amp; vbNewLine &amp; " &lt;Parameter Name=""input"" Type=""nvarchar(max)"" Mode=""In"" /&gt;" &amp; vbNewLine &amp; " &lt;Parameter Name=""pattern"" Type=""nvarchar"" Mode=""In"" /&gt;" &amp; vbNewLine &amp; " &lt;Parameter Name=""isIgnoreCase"" Type=""bit"" Mode=""In"" /&gt;" &amp; vbNewLine &amp; " &lt;Parameter Name=""groupnum"" Type=""int"" Mode=""In"" /&gt;" &amp; vbNewLine &amp; " &lt;/Function&gt;" &amp; vbNewLine &amp; " &lt;Function Name=""RegexReplace"" ReturnType=""nvarchar"" Aggregate=""false"" BuiltIn=""false"" NiladicFunction=""false"" IsComposable=""true"" ParameterTypeSemantics=""AllowImplicitConversion"" Schema=""dbo""&gt;" &amp; vbNewLine &amp; " &lt;Parameter Name=""input"" Type=""nvarchar(max)"" Mode=""In"" /&gt;" &amp; vbNewLine &amp; " &lt;Parameter Name=""pattern"" Type=""nvarchar"" Mode=""In"" /&gt;" &amp; vbNewLine &amp; " &lt;Parameter Name=""replacement"" Type=""nvarchar"" Mode=""In"" /&gt;" &amp; vbNewLine &amp; " &lt;Parameter Name=""isIgnoreCase"" Type=""bit"" Mode=""In"" /&gt;" &amp; vbNewLine &amp; " &lt;/Function&gt;" &amp; vbNewLine &amp; "&lt;/Schema&gt;")]</InArgument>
</Assign.Value>
</Assign>
<mdedda1:SsdlToDdlActivity TemplatePath="{x:Null}" DdlOutput="[Ddl]" ExistingSsdlInput="[ExistingSsdl]" sap2010:WorkflowViewState.IdRef="SsdlToDdlActivity_1" SsdlInput="[Ssdl]" />
<sads:DebugSymbol.Symbol>d5kBQzpcUHJvZ3JhbSBGaWxlcyAoeDg2KVxNaWNyb3NvZnQgVmlzdWFsIFN0dWRpbyAxMS4wXENvbW1vbjdcSURFXEV4dGVuc2lvbnNcTWljcm9zb2Z0XEVudGl0eSBGcmFtZXdvcmsgVG9vbHNcREJHZW5cVGFibGVQZXJUeXBlU3RyYXRlZ3kuV2l0aC5GdW5jdGlvbi54YW1sDTIDPg4CAQEzBTPGAwIBDTQFOw4CAQk8BTy4AQIBAjMwMzgCARQzuwMzwwMCARIzgAEzhwECARAznwEznAICAQ8zsQIzrwMCAQ42MTY3AgEKPFw8bAIBBzxCPEkCAQU8rQE8tQECAQM=</sads:DebugSymbol.Symbol>
</Sequence>
<sap2010:WorkflowViewState.ViewStateManager>
<sap2010:ViewStateManager>
<sap2010:ViewStateData Id="CsdlToSsdlAndMslActivity_1" sap:VirtualizedContainerService.HintSize="243,22" />
<sap2010:ViewStateData Id="Assign_2" sap:VirtualizedContainerService.HintSize="243,61" />
<sap2010:ViewStateData Id="SsdlToDdlActivity_1" sap:VirtualizedContainerService.HintSize="243,22" />
<sap2010:ViewStateData Id="Sequence_1" sap:VirtualizedContainerService.HintSize="265,309">
<sap:WorkflowViewStateService.ViewState>
<scg:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg:Dictionary>
</sap:WorkflowViewStateService.ViewState>
</sap2010:ViewStateData>
<sap2010:ViewStateData Id="GenerateDatabaseScriptWorkflow_1" sap:VirtualizedContainerService.HintSize="305,389" />
</sap2010:ViewStateManager>
</sap2010:WorkflowViewState.ViewStateManager>
</Activity>

因大字段导致的outofmemory内存溢出问题

    解决了CLR函数报错的问题后,发现又存在性能问题,原因在于审核历史记录表AuditHistory中字段ItemContent存的是json字符串,而这个字符串很大很大,所以如果查询的数据量很大的话,就会报out of memory内存溢出的错误。

    数据库数据类型及数据:

解决方案:

1,只查询需要的字段,并且先不要包含ItemContent,因为该字段内容太大。

2,ItemContent改为二进制存储

    方法1只是临时的解决方案,因为查询出结果后,后面会foreach,拿到每条记录的ItemContent并反序列化,因为我前面没有包括这个字段,所以每条记录在反序列化之前还会去查一次数据库为了拿到ItemContent,这样如果数据量一大,就会有可能查询超时。

    要想从根本上解决这个问题,最好的方法是将ItemContent改为二进制存储,这样体积就会小很多。

    保存为二进制:var localResponse = localRS.ToBinary();

/// <summary>
/// 对象转换binary
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static byte[] ToBinary(this object input)
{
var jsonStr = input.ToJson();
if (!jsonStr.IsNullOrEmpty())
{
return jsonStr.GZipCompress();
}
return null;
}

    拿到二进制数据反序列化:

/// <summary>
/// binary转换对象
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static T FromBinary<T>(this byte[] input)
{
var jsonStr = input.GZipDecompress();
if (!jsonStr.IsNullOrEmpty())
{
return jsonStr.FromJson<T>();
}
return default(T);
}

解决一个报表EdmFunction报错问题的更多相关文章

  1. 目标平台、活动平台 配置,出现未能加载文件或程序集“xxx”或它的某一个依赖项报错

    今天在做动态加载程序集的时候,发现明明程序集存在的情况下,还是依然报“未能加载文件或程序集“xxx”或它的某一个依赖项报错”的错误,排除了程序和配置的错误后,怀疑是否是环境的问题,于是百度加msdn后 ...

  2. 解决element-ui upload组件报错 Avoid using non-primitive value as key, use string/number value instead

    到底是啥错呢,就是要求你的key必须是string或者number类型 那么解决就是找到这个报错的key(在node_modules/element-ui/lib/element-ui.common. ...

  3. 解决Navicat连接mysql报错:1862 - Your password has expired. To log in you must change it using a client that supports expired passwords.

    今天尝试用Navicat连接mysql时,发现一个1862的报错问题: 后来参照这篇文章https://blog.csdn.net/u010513756/article/details/5073501 ...

  4. 解决vue安装less报错Failed to compile with 1 errors的问题

    1.创建vue项目后安装less,执行 npm install less less-loader --save-dev 下载版本为:less-loader@6.1.0 , less@3.11.3,重启 ...

  5. 解决eclipse spring配置报错:cvc-elt.1: Cannot find the declaration of element

    解决eclipse spring配置报错:cvc-elt.1: Cannot find the declaration of element 'beans'.Referenced file conta ...

  6. Mysql备份迁移——MySqlBackup(.net)——(无法解决视图嵌视图报错)

    这里是利用MySqlBackup,可以再nuget中下载. 无法解决视图嵌视图报错的问题,只导表跟数据比较合适,如果有视图嵌视图,请参照Mysql备份迁移——Mysqldump(.NET调用Mysql ...

  7. 解决cookies存储中文报错问题

    URLEncoder.encode("username", "UTF-8"); URLDecoder.decode("123", " ...

  8. 解决spring boot启动报错java.lang.NoClassDefFoundError: ch/qos/logback/classic/Level

    解决spring boot启动报错java.lang.NoClassDefFoundError: ch/qos/logback/classic/Level 学习了:https://blog.csdn. ...

  9. this.$Message.success('提示信息') 少写了一个c 导致报错

    this.$Message.success('提示信息') 少写了一个c 导致报错 而且 $Message 输出还没显示,导致我以为是没有 $Message 对象了,其实全局对象直接调用即可

随机推荐

  1. 一张png图片 上面有多个图标,如何用CSS准确的知道其中某个图片的坐标

    一张png图片 上面有多个图标,如何用CSS准确的知道其中某个图片的坐标 ,如下图 可以使用  background background:url(images/xx.png) 40px 10px n ...

  2. Java垃圾回收算法和垃圾回收器

    基本上 jvm内存回收有三种 基本算法 标记-清除 标记清除的算法最简单,主要是标记出来需要回收的对象,然后然后把这些对象在内存的信息清除.如何标记需要回收的对象,在上一篇文章里面已经有说明. 标记- ...

  3. 《易货》Alpha版本测试报告

    一.测试计划 功能需求编号 功能需求名称 功能需求描述 测试计划 1 用户注册 每一个想要发布商品或者需要购买商品的用户都需要注册一个账号 √ 2 用户登录 已经拥有账号的用户登录 √ 3 密码修改 ...

  4. Android手机_软件安装目录

    1. /data/data ==> 应该是 数据存放的位置 /data/app ==> 应该是 程序存放的位置 2.

  5. poj3384Feng Shui(半平面交)

    链接 将边长向内推进r,明显这样把第一个圆的圆心放在新的边长是肯定是最优的,与原本边相切,然后再找新多边上的最远的两点即为两圆心. #include <iostream> #include ...

  6. sscanf的用法(转)

    队长做上海邀请赛的I题时遇到一个棘手的问题,字符串的处理很麻烦,按传统的gets全部读入的话还要做N多处理,太浪费时间. 回来之后搜了一下sscanf的用法发现可以很好的解决这一类问题,各种百度,转来 ...

  7. hdu 1142 用优先队列实现Dijkstra

    之前很认真地看了用优先队列来实现Dijkstra这块,借鉴了小白书上的代码模板后,便拿这道题来试试水了.这道题的大意就是问你从地点1到地点2有多少条满足条件的路径(假设该路径经过 1->...- ...

  8. Handler详解系列(四)——利用Handler在主线程与子线程之间互发消息,handler详解

    MainActivity如下: package cc.c; import android.app.Activity; import android.os.Bundle; import android. ...

  9. 使用node js 操作 Mysql 数据库

    使用node js 操作 Mysql 数据库 http://www.nodejs.org/ //node js 数据库操作 MySQL //使用https://github.com/felixge/n ...

  10. MIRO校验过程

    一.介绍发票校验是物料管理(MM)系统的一部分.它提供物料管理部分和财务会计, 成本控制和资产管理部分的连接.物料管理模块的发票校验为以下目的服务:它完成物料采购的全过程 - 物料采购从采购申请开始, ...