Has anyone a suggestion of how to make this function supported by 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? and all database fields.
Make your IsEnabled
method return an expression.
See here: 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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With