简体   繁体   English

Web API控制器POST请求通过字符串数组进行LINQ搜索

[英]Web API Controller POST Request LINQ search through String Array

I have the following database structure. 我有以下数据库结构。

结构体

Sorry for the horrible MS Paint Work 对不起,MS Paint的工作很糟糕

I am using .NET Framework 4.6.1 Web API Controller using Entity Framework. 我正在使用使用实体框架的.NET Framework 4.6.1 Web API控制器。

My API Controller handles a post request that receives a structure similar to: 我的API控制器处理后请求,该请求接收的结构类似于:

{  "countryCode": "CA", "languageCode": "EN ","partTypes": "Brakes", "partComponents": "Relay" }

^^ Above request should find Part ID = 1 , and I want to select Part Request URL ^^上面的请求应该找到Part ID = 1,我想选择Part Request URL

{ "countryCode": "US","languageCode": "EN ","partTypes": " Brakes , Clutch", "partComponents": "Relay"}

^^ Above request should find Part ID = 1 & 2 , and I want to select Part Request URL for both. ^^上面的请求应该找到Part ID = 1&2,我想为两者都选择Part Request URL。

“Clutch, Resistor, EN, US” Should find Part ID = 2 etc. “离合器,电阻器,EN,US”应找到零件ID = 2等。

My Question is how am I able to use LINQ to SQL or <IQueryable> to return the part ID for whatever post request is captured by the controller. 我的问题是我如何使用LINQ to SQL或<IQueryable>来为控制器捕获的任何后期请求返回部件ID。 The current code I have been working on so far looks similar to this: 到目前为止,我正在研究的当前代码类似于以下内容:

Inside API Controller: 内部API控制器:

public string Post(PostProfile postProfile) 
string[] partURLArray;
{
using (var context = new context())
{partURLArray = context.ViewName
.Where(fields = > field.CountryCode.Contains(postProfile.countryCode)
.Where(fields => fields.LanguageCode.Contains(postProfile.languageCode)
.Select(fields => fields.PartRequestURL).ToArray();
}
foreach 
(var part in partURLArray)
{
//do some stuff
}
return partString
}

Post Profile Model Class: 发布个人资料模型类别:

    public string countryCode { get; set; }
    public string languageCode { get; set; }
    public string[] partType { get; set; }
    public string[] partComponents { get; set; }

You answer isn't clear for and I cannot fully understand what you are want to do. 您的答案尚不清楚,我无法完全理解您想要做什么。 As I understand you want to return Part1 and Part2 urls in one Query. 据我了解,您想在一个查询中返回Part1和Part2的URL。 If is true.Got it 如果是真的,知道了

 using (var context = new context())
 {partURLArray = context.ViewName
 .Where(fields = > field.CountryCode.Contains(postProfile.countryCode)
  OR fields.LanguageCode.Contains(postProfile.languageCode)
 .Select(fields => fields.PartRequestURL).ToArray(); 

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

相关问题 发布请求期间未击中Web Api控制器 - Web Api Controller not hitting during post request 为什么Web API控制器通过POST请求从客户端获取空数据? - Why does the Web API controller get null data from client through POST request? 如何通过Web API中的post请求接收流和对象? - How to receive stream and object through post request in Web API? 如何将数组从HttpClient发布到Web api控制器? - How do I POST an array to a web api controller from an HttpClient? WEB API2获取POST请求JSON数组值 - WEB API2 getting POST request JSON array values 如何使用Alamofire POST请求将图像作为Base64String发送以及如何在Asp.net MVC4 web Api控制器中处理请求? - How to Send Image as Base64String using Alamofire POST request and how to handle the request in Asp.net MVC4 web Api Controller? 在LINQ表达式中的字符串数组中搜索字符串 - Search string within a string array in a LINQ expression Web Api 中的 Post 请求中的请求正文为空 - Request Body is null in Post request in Web Api 从Web API控制器重定向POST请求时,处理100-继续 - Handling 100-continue when redirecting a POST request from a Web API controller 从ASP.Net核心Web API中的发布请求在基础控制器中分配值 - Assign Value In Base Controller From Post Request In ASP.Net core web API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM