Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在ASP.NETMVC4项目中使用LINQtoSQL中Where子句中的函数_Asp.net_Asp.net Mvc 4_Linq To Sql - Fatal编程技术网

在ASP.NETMVC4项目中使用LINQtoSQL中Where子句中的函数

在ASP.NETMVC4项目中使用LINQtoSQL中Where子句中的函数,asp.net,asp.net-mvc-4,linq-to-sql,Asp.net,Asp.net Mvc 4,Linq To Sql,我在ASP.NETMVC4应用程序中使用LINQtoSQL编写了以下代码 private bool isFallInCurrentSeason(DateTime? dt) { if ({condition}) return true; else return false; } public IQueryable<T> FindByLocId(int locId) { var records = from l in db.Ts

我在ASP.NETMVC4应用程序中使用LINQtoSQL编写了以下代码

private bool isFallInCurrentSeason(DateTime? dt)
{
  if ({condition})
    return true;
  else
    return false;
}

public IQueryable<T> FindByLocId(int locId)
{
  var records = from l in db.Ts
                  where (l.LocationId == locId)
                  where ((l.ObservationStatus == 0) || isFallInCurrentSeason(l.FinalisedDate.value))
                  orderby l.ObservationId
                  select l;

  return records;
}
谁能告诉我怎么修理它吗?谢谢


大家好,Alex

LINQ to SQL试图将您的查询转换为SQL。它基于表达式树工作。LINQtoSQL查询提供程序不知道如何将方法调用转换为正确的SQL文本,这就是为什么会出现异常


您应该在查询中内联您的条件,以便编译器生成正确的表达式树生成代码。

我想使函数可重用,以便在其他查询函数中使用它。
Method 'Boolean isFallInCurrentSeason(DateTime? dt)' has no supported translation to SQL.