Hi, I've implemented a search-query. It replaces special chars with "normalized" ones. I've apply this rule on different fields. Actually, the query looks very ugly and is full of DRY-violations.
But refacotring this, doesn't seem to be an easy thing (for me). Of course, I just tried to refactor the whole Replace-Stuff into a separate method, but this resulted in an error like
LINQ to Entities does not recognize the method 'System.String Help(System.String)' method, and this method cannot be translated into a store expressio...
The code below shows a part of the query, there are even more statements like this in it. If somebody would have an idea, to make this nicer, it would be great!
qry = qry.Where(guest =>
(guest.FirstName
.Replace("ü", "u").Replace("ue", "u").Replace("û", "u").Replace("ù", "u").Replace("ú", "u")
.Replace("ä", "a").Replace("ae", "a").Replace("â", "a").Replace("à", "a").Replace("á", "a")
.Replace("ë", "e").Replace("ê", "e").Replace("è", "e").Replace("é", "e")
.Replace("ö", "o").Replace("oe", "o").Replace("ô", "o").Replace("ò", "o").Replace("ó", "o")
.Replace("ï", "i").Replace("ì", "i").Replace("ì", "i").Replace("í", "i")
.Replace("ç", "c")
.Replace(".", "").Replace("-", "").Replace("_", "").Replace("´", "").Replace("'", "").Replace("\"", "")
.Replace("(", "").Replace(")", "").Replace("[", "").Replace("]", "").Replace("{", "").Replace("}", "")
.Replace("$", "").Replace("+", "").Replace("*", "").Replace("@", "")
.Replace("|", "").Replace("\\", "").Replace("/", "").Replace("<", "").Replace(">", "")
.Replace(".", "").Replace(",", "").Replace(";", "").Replace(":", "")
.Replace("=", "").Replace("%", "").Replace("^", "").Replace("?", "").Replace("!", "")
.StartsWith(firstName)
&& (guest.LastName
.Replace("ü", "u").Replace("ue", "u").Replace("û", "u").Replace("ù", "u").Replace("ú", "u")
.Replace("ä", "a").Replace("ae", "a").Replace("â", "a").Replace("à", "a").Replace("á", "a")
.Replace("ë", "e").Replace("ê", "e").Replace("è", "e").Replace("é", "e")
.Replace("ö", "o").Replace("oe", "o").Replace("ô", "o").Replace("ò", "o").Replace("ó", "o")
.Replace("ï", "i").Replace("ì", "i").Replace("ì", "i").Replace("í", "i")
.Replace("ç", "c")
.Replace(".", "").Replace("-", "").Replace("_", "").Replace("´", "").Replace("'", "").Replace("\"", "")
.Replace("(", "").Replace(")", "").Replace("[", "").Replace("]", "").Replace("{", "").Replace("}", "")
.Replace("$", "").Replace("+", "").Replace("*", "").Replace("@", "")
.Replace("|", "").Replace("\\", "").Replace("/", "").Replace("<", "").Replace(">", "")
.Replace(".", "").Replace(",", "").Replace(";", "").Replace(":", "")
.Replace("=", "").Replace("%", "").Replace("^", "").Replace("?", "").Replace("!", "")
.StartsWith(lastName)
||
guest.LastName
.Replace("ü", "u").Replace("ue", "u").Replace("û", "u").Replace("ù", "u").Replace("ú", "u")
.Replace("ä", "a").Replace("ae", "a").Replace("â", "a").Replace("à", "a").Replace("á", "a")
.Replace("ë", "e").Replace("ê", "e").Replace("è", "e").Replace("é", "e")
.Replace("ö", "o").Replace("oe", "o").Replace("ô", "o").Replace("ò", "o").Replace("ó", "o")
.Replace("ï", "i").Replace("ì", "i").Replace("ì", "i").Replace("í", "i")
.Replace("ç", "c")
.Replace(".", "").Replace("-", "").Replace("_", "").Replace("´", "").Replace("'", "").Replace("\"", "")
.Replace("(", "").Replace(")", "").Replace("[", "").Replace("]", "").Replace("{", "").Replace("}", "")
.Replace("$", "").Replace("+", "").Replace("*", "").Replace("@", "")
.Replace("|", "").Replace("\\", "").Replace("/", "").Replace("<", "").Replace(">", "")
.Replace(".", "").Replace(",", "").Replace(";", "").Replace(":", "")
.Replace("=", "").Replace("%", "").Replace("^", "").Replace("?", "").Replace("!", "")
.Contains(" " + lastName)
||
guest.LastName.Replace(" ", "")
.Replace("ü", "u").Replace("ue", "u").Replace("û", "u").Replace("ù", "u").Replace("ú", "u")
.Replace("ä", "a").Replace("ae", "a").Replace("â", "a").Replace("à", "a").Replace("á", "a")
.Replace("ë", "e").Replace("ê", "e").Replace("è", "e").Replace("é", "e")
.Replace("ö", "o").Replace("oe", "o").Replace("ô", "o").Replace("ò", "o").Replace("ó", "o")
.Replace("ï", "i").Replace("ì", "i").Replace("ì", "i").Replace("í", "i")
.Replace("ç", "c")
.Replace(".", "").Replace("-", "").Replace("_", "").Replace("´", "").Replace("'", "").Replace("\"", "")
.Replace("(", "").Replace(")", "").Replace("[", "").Replace("]", "").Replace("{", "").Replace("}", "")
.Replace("$", "").Replace("+", "").Replace("*", "").Replace("@", "")
.Replace("|", "").Replace("\\", "").Replace("/", "").Replace("<", "").Replace(">", "")
.Replace(".", "").Replace(",", "").Replace(";", "").Replace(":", "")
.Replace("=", "").Replace("%", "").Replace("^", "").Replace("?", "").Replace("!", "")
.StartsWith(lastName))
) || (
guest.FirstName
.Replace("ü", "u").Replace("ue", "u").Replace("û", "u").Replace("ù", "u").Replace("ú", "u")
.Replace("ä", "a").Replace("ae", "a").Replace("â", "a").Replace("à", "a").Replace("á", "a")
.Replace("ë", "e").Replace("ê", "e").Replace("è", "e").Replace("é", "e")
.Replace("ö", "o").Replace("oe", "o").Replace("ô", "o").Replace("ò", "o").Replace("ó", "o")
.Replace("ï", "i").Replace("ì", "i").Replace("ì", "i").Replace("í", "i")
.Replace("ç", "c")
.StartsWith(lastName)
&& (guest.LastName
.Replace("ü", "u").Replace("ue", "u").Replace("û", "u").Replace("ù", "u").Replace("ú", "u")
.Replace("ä", "a").Replace("ae", "a").Replace("â", "a").Replace("à", "a").Replace("á", "a")
.Replace("ë", "e").Replace("ê", "e").Replace("è", "e").Replace("é", "e")
.Replace("ö", "o").Replace("oe", "o").Replace("ô", "o").Replace("ò", "o").Replace("ó", "o")
.Replace("ï", "i").Replace("ì", "i").Replace("ì", "i").Replace("í", "i")
.Replace("ç", "c")
.Replace(".", "").Replace("-", "").Replace("_", "").Replace("´", "").Replace("'", "").Replace("\"", "")
.Replace("(", "").Replace(")", "").Replace("[", "").Replace("]", "").Replace("{", "").Replace("}", "")
.Replace("$", "").Replace("+", "").Replace("*", "").Replace("@", "")
.Replace("|", "").Replace("\\", "").Replace("/", "").Replace("<", "").Replace(">", "")
.Replace(".", "").Replace(",", "").Replace(";", "").Replace(":", "")
.Replace("=", "").Replace("%", "").Replace("^", "").Replace("?", "").Replace("!", "")
.StartsWith(firstName)
||
guest.LastName
.Replace("ü", "u").Replace("ue", "u").Replace("û", "u").Replace("ù", "u").Replace("ú", "u")
.Replace("ä", "a").Replace("ae", "a").Replace("â", "a").Replace("à", "a").Replace("á", "a")
.Replace("ë", "e").Replace("ê", "e").Replace("è", "e").Replace("é", "e")
.Replace("ö", "o").Replace("oe", "o").Replace("ô", "o").Replace("ò", "o").Replace("ó", "o")
.Replace("ï", "i").Replace("ì", "i").Replace("ì", "i").Replace("í", "i")
.Replace("ç", "c")
.Replace(".", "").Replace("-", "").Replace("_", "").Replace("´", "").Replace("'", "").Replace("\"", "")
.Replace("(", "").Replace(")", "").Replace("[", "").Replace("]", "").Replace("{", "").Replace("}", "")
.Replace("$", "").Replace("+", "").Replace("*", "").Replace("@", "")
.Replace("|", "").Replace("\\", "").Replace("/", "").Replace("<", "").Replace(">", "")
.Replace(".", "").Replace(",", "").Replace(";", "").Replace(":", "")
.Replace("=", "").Replace("%", "").Replace("^", "").Replace("?", "").Replace("!", "")
.Contains(" " + firstName)
||
guest.LastName.Replace(" ", "")
.Replace("ü", "u").Replace("ue", "u").Replace("û", "u").Replace("ù", "u").Replace("ú", "u")
.Replace("ä", "a").Replace("ae", "a").Replace("â", "a").Replace("à", "a").Replace("á", "a")
.Replace("ë", "e").Replace("ê", "e").Replace("è", "e").Replace("é", "e")
.Replace("ö", "o").Replace("oe", "o").Replace("ô", "o").Replace("ò", "o").Replace("ó", "o")
.Replace("ï", "i").Replace("ì", "i").Replace("ì", "i").Replace("í", "i")
.Replace("ç", "c")
.Replace(".", "").Replace("-", "").Replace("_", "").Replace("´", "").Replace("'", "").Replace("\"", "")
.Replace("(", "").Replace(")", "").Replace("[", "").Replace("]", "").Replace("{", "").Replace("}", "")
.Replace("$", "").Replace("+", "").Replace("*", "").Replace("@", "")
.Replace("|", "").Replace("\\", "").Replace("/", "").Replace("<", "").Replace(">", "")
.Replace(".", "").Replace(",", "").Replace(";", "").Replace(":", "")
.Replace("=", "").Replace("%", "").Replace("^", "").Replace("?", "").Replace("!", "")
.StartsWith(firstName))
));