我正在从客户端获取一个字符串列表(他选择的项目),现在我需要从数据库返回结果。客户请求是:
List<string> campaignStrings
列出示例:
[0]-“ 292 | Mac / 6月17日”
[1]-“ 161 | Direct / June 17”
我尝试的没有成功的方法是:
var campaigns = ctx.V_CommercialCampaigns.Where(cam => campaignStrings.Any(x => cam.Name.Contains(x))).Select(id => id.Id).ToList();
我使用“包含”,因为“名称”列可能与搜索词不同。
我在做什么错了?
答案 0 :(得分:2)
如果要检查export class GithubService {
baseUrlSearch ="https://api.github.com/search";
initResponse:IResponse = {total_count:0,incomplete_results:false,items:[]}
//subject = new Subject<IResponse>();
subject = new BehaviorSubject<IResponse>(this.initResponse);
constructor(private http: HttpClient) { }
public setSearch(newSearchText:string):void{
if (newSearchText.length<=3) return;
const url=`${this.baseUrlSearch}/users?q=${newSearchText}`;
this.http.get<IResponse>(url).pipe(debounceTime(500)).subscribe(
res=> this.subject.next(res));
}
public getResults():Observable<IResponse>
{
return this.subject.asObservable();
}
// ListComponent class
export class ListComponent implements OnInit {
response$: Observable<IResponse>;
constructor (private service :GithubService)
{}
ngOnInit(): void {
this.response$= this.service.getResults();
}
}
是否出现在cam.Name
列表中,则需要将campaignStrings
子句更改为此:
where
答案 1 :(得分:1)
尝试此解决方案
<details>
<summary>Details</summary>
Something small enough to escape casual notice.
</details>