无法使用实体框架搜索记录 [英] Unable to search records using entity framework

查看:97
本文介绍了无法使用实体框架搜索记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在数据库和显示中搜索和记录。但搜索不起作用我收到错误,如Error =函数评估需要所有线程运行。 dbcontext没有返回任何行。



我尝试过:



I want to search and for records in the DB and display. But the search is not working i am getting an error like Error = The function evaluation requires all threads to run. The dbcontext not returning any rows.

What I have tried:

[HttpPost]
        public ActionResult Search( string Search)
        {
             
            var emp = from m in db.Emps
                      select m;

            if (emp != null)
            {
              var ttt = db.Emps.Where(s => s.Name.Contains(Search));
               
            }

            else
            {
                ModelState.AddModelError("Name"," No records found");

            }
            return View(emp);
        }







@using (Html.BeginForm("Search", "Emps", FormMethod.Post))
{

    <div class="container form-group">
        <input class="form-control" type="text" id="Mail" name="Search">

    </div>

    @*@Html.TextBox("SearchText")*@
    <div class="form-group">
        <input type="submit" value="Search" id="searching" class="btn btn-default mysquare" />
    </div>

}

@if (Model != null)
{
    foreach (var person in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelitem => person.ID)
            </td>
        </tr>
        <tr>
            <td>
                @Html.DisplayFor(modelitem => person.Name)
            </td>
        </tr>
        <tr>
            <td>
                @Html.DisplayFor(modelitem => person.City)
            </td>
        </tr>
        <tr>
            <td>
                @Html.DisplayFor(modelitem => person.Designation)
            </td>
        </tr>
        <tr>
            <td>
                @Html.DisplayFor(modelitem => person.Country)
            </td>
        </tr>
        <tr>
            <td>
                @Html.DisplayFor(modelitem => person.Mail)
            </td>
        </tr>
    }
}

推荐答案

读取此内容


c# - Visual调试期间的Studio:函数评估需要运行所有线程 - Stack Overflow [ ^ ]



不知道引发异常的位置除了阅读上述内容之外,我不能提出任何建议。



另外我还会将代码更改为以下内容



have a read of this

c# - Visual Studio during Debugging: The function evaluation requires all threads to run - Stack Overflow[^]

without knowing where the exception is raised I can't suggest anything other than having a read of the above.

Plus I would also change the code to something like the following

var foundEmployees = db.Emps.Where(s => s.Name.Contains(Search));
if(foundEmployees == null) ModelState.AddModelError("Name"," No records found");
return foundEmployees;


这篇关于无法使用实体框架搜索记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆