[英]Method X has no supported translation to SQL - booleans and datetime
Has anyone a suggestion of how to make this function supported by LINQ to SQL? 有没有人建议如何使LINQ to SQL支持此功能?
public bool IsEnabled()
{
return !this.Disabled &&
((!this.EnabledFrom.HasValue || this.EnabledFrom < DateTime.Now) &&
(!this.EnabledTo.HasValue || this.EnabledTo > DateTime.Now));
}
Disabled is a bool, EnabledFrom and EnabledTo is DateTime? 禁用是一个布尔值,EnabledFrom和EnabledTo是DateTime吗? and all database fields. 和所有数据库字段。
Make your IsEnabled
method return an expression. 使您的IsEnabled
方法返回一个表达式。
See here: http://www.atrevido.net/blog/2007/09/05/Calling+Custom+Methods+In+LINQtoSQL.aspx 看到这里: http : //www.atrevido.net/blog/2007/09/05/Calling+Custom+Methods+In+LINQtoSQL.aspx
Something like below (untested): 如下所示(未试用):
static Expression<Func<Account, bool>> IsEnabled = a =>
!a.Disabled &&
((!a.EnabledFrom.HasValue || a.EnabledFrom < DateTime.Now) &&
(!a.EnabledTo.HasValue || a.EnabledTo > DateTime.Now));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.