使用linq

时间:2019-04-12 14:54:16

标签: asp.net-mvc-4

我正在尝试在页面上执行搜索操作。我的数据库中有3个表,两者之间没有任何关系。我创建了一个名为SearchModel的视图模型,并尝试将查询数据发送到如下所示的视图

我对ASP.NET *很陌生

IQueryable<SearchModel> t = Enumerable.Empty<SearchModel>().AsQueryable();

var searchD = from d in db.domains
              where d.domainName.Contains(search) //search is the search string
              select d;
var searchU = from u in db.users
              where u.userName.Contains(search)
              select u;
var searchA = from a in db.adminLists
              where a.userName.Contains(search)
              select a;
t.searchDomain = searchD;
t.searchAdmin = searchA;
t.searchUsers = searchU;
return view(t);

我说错了

IQueryable<SearchModel>' does not contain a definition for 'searchDomain'
and no accessible extension method 'searchDomain' accepting a first argument of type
'IQueryable<SearchModel>' could be found (are you missing a using directive or an assembly reference?)

这是我的视图模型

public class SearchModel
{
    public user searchUsers { get; set; }
    public adminList searchAdmin { get; set; }
    public domain searchDomain { get; set; }
}

是否缺少某些内容和/或有更好的搜索方式?

0 个答案:

没有答案