LINQ와 엔티티 프레임 워크와 일치하는 복잡한 문자열
-
05-07-2019 - |
문제
우리는 솔루션을 개발하기 위해 LINQ에서 EF를 사용하고 있습니다.
LINQ 쿼리에서 원하는 쿼리에서
string toMatch = "Matt Cool";
newString = toMatch.Replace(" ", "% ") + "%";
// So here newString is 'Matt% Cool%'
/*Now in my datasource, there is no 'Matt Cool', there's 'Matthew Coolguy'.
I would like this query to return that result.
I would expect this behavior with the
wildcard. It doesn't work*/
var results = from a in mycontainer.users
where a.fullname.equals(newString)
select a.fullname;
"*"는 와일드 카드와 정규식 솔루션으로 시도했습니다. 다른 옵션이 있습니까?
해결책
사용하는 대신 동등합니다 사용해보십시오 포함 내부 LINQ를 사용하기 때문에 와일드 카드를 사용해야합니다. 처럼 당신이 사용할 때 포함
var results = from a in mycontainer.users
where a.fullname.Contains(newString)
select a.fullname;
다른 팁
방법을 설명하는 훌륭한 기사가 있습니다.엔티티 프레임 워크의 정규식
제휴하지 않습니다 StackOverflow