Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/81.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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
Sql .NET MVC检查查询是否不为null并显示部分视图_Sql_Linq - Fatal编程技术网

Sql .NET MVC检查查询是否不为null并显示部分视图

Sql .NET MVC检查查询是否不为null并显示部分视图,sql,linq,Sql,Linq,我想检查我的查询是否返回行,如果是,则显示部分视图 以下是我到目前为止的情况: [ChildActionOnly] public ActionResult GetMembership(int id) { var membership = from m in db.CustomerEnrollment where m.CustomerID == id && m.CustomerTypeID == "1" &

我想检查我的查询是否返回行,如果是,则显示部分视图

以下是我到目前为止的情况:

[ChildActionOnly]
    public ActionResult GetMembership(int id)
    {
        var membership = from m in db.CustomerEnrollment
                      where m.CustomerID == id && m.CustomerTypeID == "1" && m.EndDate >= DateTime.UtcNow
                      orderby m.StartDate
                      select m;
        return PartialView("_GetMembership", membership);
    }
现在我只需要检查是否有行

这是近在咫尺还是我远在天边

        if (membership != null)
        {
            return PartialView("_GetMembership", membership);
        }
使用:


现在工作!我需要添加returnnull;在if语句下面。
if(membership.Any()){...}