简体   繁体   English

在ASP.NET Web API和实体框架中搜索数据

[英]Search data in asp.net web api and Entity Framework

I want to find a name records For example i have two record 我想查找一个姓名记录例如,我有两个记录

<Employee>
<Name>Jone</Name>
<Address>United Kingdom</Address>
<Phone>0123456789</Phone>
</Employee>
------------------
<Employee>
<Name>Ronaldo</Name>
<Address>Portugal</Address>
<Phone>0123456789</Phone>
</Employee>

i'd like for example implement: 我想例如实施:

http://localhost:18179/Api/Employee/Search/ronal

ronal is string from keyboard. ronal是键盘上的字符串。 Result 结果

<Employee>
<Name>Ronaldo</Name>
<Address>Portugal</Address>
<Phone>0123456789</Phone>
</Employee>

I tried to but not ok. 我试图但不行。

public List<Employee> SearchList(string name)
        {
            var store = db.Employyes.Where(a => a.Name.Contains(name)).ToList();
            return store;
        }

You need to define a route using, for example, [HttpGet] and [Route]: 您需要使用例如[HttpGet]和[Route]定义路由:

[HttpGet]
[Route("search/{name}")]
public List<Employee> Search(string name)
{
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用ASP.NET Web API和实体框架进行API版本控制 - API Versioning with ASP.NET Web API and Entity Framework breezejs和ASP.NET Web Api OData中的实体框架继承 - Entity Framework Inheritance in breezejs and ASP.NET Web Api OData 使用实体框架的ASP.NET Web API 2 CRUD操作 - ASP.NET Web API 2 CRUD Operation with Entity Framework 什么是最好的带有Asp.Net Web Api的实体框架或存储库 - What is preferable Entity Framework or Repository with Asp.Net Web Api Asp.net web api +实体框架:多个请求导致数据冲突 - Asp.net web api + entity framework: multiple requests cause data conflict ASP.NET Core MVC 1.3 Web API + Entity Framework,我无法按名称搜索数据库,但可以按 ID - ASP.NET Core MVC 1.3 Web API + Entity Framework, I can't search a database by name, but I can by id 使用2实体框架ASP.Net API - Working with 2 Entity Framework ASP.Net API 我如何在Asp.Net MVC中使用Entity Framework和Web Api获取外键表数据 - How do i get foreign key table data using Entity Framework and Web Api in Asp.Net MVC 如何使用 JSON 处理具有“父子”关系的数据的 POST 调用 - How to handle POST call with JSON having data with “parent-child” relationship using ASP.NET Web API Entity Framework? ASP.NET实体框架更新数据 - ASP.NET Entity Framework Update Data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM