实体框架无法识别我的将路由对象转换为特定字符串的 ToString 方法:
public IEnumerable<Route> GetRoutes(string prefix, string searchPattern, string code)
{
return Routes.
Where(x => code == null || x.Code == code).
Where(x => searchPattern == null || x.ToString().Contains(searchPattern)).
Where(x => prefix == null || x.ToString().StartsWith(prefix));
}
这是我的路线实体:
public class Route : IDataEntity, ISoftDeletable
{
public virtual long Id { get; set; }
public virtual string Code { get; set; }
public virtual bool IsDeleted { get; set; }
public virtual Guid CompanyId { get; set; }
public virtual IList<LocationInRoute> Locations { get; set; }
public override string ToString()
{
StringBuilder str = new StringBuilder();
foreach (LocationInRoute loc in Locations)
{
if (str.Length > 0)
{
str.Append(" > ");
}
str.Append(loc.ToString());
}
return str.ToString();
}
}
All the x.ToString()
抛出 linq toEntity 中不支持的异常。
有什么解决办法吗?
您不能在客户端执行此操作(ToString
).
您必须创建将进行评估的 SQL 函数 - 它可以仅对您的位置进行字符串连接(我相信它是相关实体),或者您可以在自定义函数中进行整个测试。然后您可以将该函数导入到实体模型 (EDMX) 中并创建EdmFunctionAttribute
称之为 -MSDN http://msdn.microsoft.com/en-us/library/dd456847.aspx.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)