Anyone know how to do this query? I know I can usar a start with and EndWith, but I have to parse the string and I can have %2324%335% and now? Any way to do this easy?
Asked
Active
Viewed 460 times
2
-
This post http://stackoverflow.com/questions/1033007/like-operator-in-entity-framework suggest that LIKE is not supported in EF. However this post is from back when EF1 was the current, so EF4 may be different in this respect. – Andrew Savinykh May 04 '11 at 23:59
2 Answers
6
You can create a custom function:
<Function Name="String_Like" ReturnType="Edm.Boolean">
<Parameter Name="searchingIn" Type="Edm.String" />
<Parameter Name="lookingFor" Type="Edm.String" />
<DefiningExpression>
searchingIn LIKE lookingFor
</DefiningExpression>
</Function>
And call it using
[System.Data.Objects.DataClasses.EdmFunction( "Your.Namespace", "String_Like")]
public static Boolean Like(this String searchingIn, String lookingFor) {
throw new Exception("Not implemented");
}

SLaks
- 868,454
- 176
- 1,908
- 1,964
-
Use the `Like` extension method in a query; see http://jendaperl.blogspot.com/2011/02/like-in-linq-to-entities.html. Note that I haven't tried this. – SLaks May 05 '11 at 00:17
-
I get this error: Error 507 Namespace prefix 'ef4ex' is not defined. – Jedi Master Spooky May 05 '11 at 18:43
-
-
Now I get this: {"The specified method 'Boolean Like(System.String, System.String)' on the type 'LCP.RM.Dal.EntityFramework.Design.HelperMethods' cannot be translated into a LINQ to Entities store expression."} – Jedi Master Spooky May 05 '11 at 19:10
-
Awesome! Putting the Like-Function into a static class with name abc works great and then you need to call it on a property of type string inside the where function with LINQ! This solves many problems we had by using SQLQuery to archieve using LIKE on a odata/entitfy framework wcf data service. – Sebastian May 22 '15 at 06:44