【发布时间】:2015-06-04 21:42:06
【问题描述】:
我有一个带有 .edmx 文件的 ASP.NET 4.0 MVC 项目,使用 Linq to Entities。我在概念模型中添加了一个函数,但出现“不支持”错误。
EF 版本:
<package id="EntityFramework" version="6.1.3" targetFramework="net40" />
这里是 edmx 部分:
<edmx:ConceptualModels>
<Schema Namespace="MillCertsModel" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2009/11/edm" annotation:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation">
... EntityType elements ...
<Function Name="IsLike" ReturnType="Edm.Boolean">
<Parameter Name="str" Type="Edm.String" />
<Parameter Name="pattern" Type="Edm.String" />
<DefiningExpression>
str LIKE pattern
</DefiningExpression>
</Function>
</Schema>
</edmx:ConceptualModels>
还有函数...
public static class Utilities
{
[System.Data.Objects.DataClasses.EdmFunction("MillCertsModel", "IsLike")]
public static bool IsLike(this string str, string pattern)
{
throw new NotSupportedException("Supported for SQL queries only.");
}
}
还有代码...
if (keywords != null)
query = query.Where(m => keywords.Any(kw => m.CertificateData.Any(cd => cd.value.ToLower() == kw || cd.value.IsLike("[^a-z]"))));
错误:LINQ to Entities 无法识别方法 'Boolean IsLike(System.String, System.String)' 方法,并且此方法无法转换为存储表达式。
【问题讨论】:
标签: c# asp.net asp.net-mvc linq linq-to-entities