Entity Framework wildcards & Linq

c# entity-framework linq odac

Question

Is it feasible to build a legitimate Linq query that uses wildcard characters?

I've read several responses on this subject that recommend using:

.Where(entity => entity.Name.Contains("FooBar"))
.Where(entity => entity.Name.EndsWith("Bar")) 
.Where(entity => entity.Name.StartsWith("Foo"))

OR developing RawSql:

var commandText =
    @"SELECT field
    FROM     table
    WHERE    field LIKE @search";

var query = new ObjectQuery<Profile>(commandText, context);
query.Parameters.Add(new ObjectParameter("search", wildcardSearch));

If the wildcard wasn't at the start or end of a string, for example, the first solution wouldn't work.searchTerm = "Foo%Bar" .

Using RawSql for the second solution bothers me and seems like a quick fix. But it does function.

The third method, which @Slauma tried out in link 2 below, is to develop something that can analyze the search word and build a legitimate Linq query. However, if the wildcard was not at the start or end of the search query, this would still not function.

So the question is: Can you create a legal Linq query that uses wildcard characters?

EDIT: It should be noted that I'm utilizing Oracle Data Access Components (ODAC/ODP) in this situation, but I don't believe it makes a significant difference.

links:

1.'oelike' Entity Framework queries

2.conditional on search word precise and wildcard searching

3.Utilizing RawSql

1
3
5/23/2017 12:24:59 PM

Popular Answer

ZZZ_tmp
2
7/18/2013 1:05:23 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow