How to write an expression for string concatenation for linq?
I have this:
x => (x.Address1 + " " + x.Address2).Contains("add")
predicate and I don’t know how to write a lambda expression for string concatenation without using string.Concat method. So I have two expressions (x.Address1 and " ") and I need to concatenate them.
UPDATE: This link has the solution: NHibernate / MySQL string concatenation
Will the string
fooin.Contains(foo)ever contain a space? If not, try Ade’s second predicate as that avoids the concatenation.If that doesn’t work you might have to get more objects out of the database than you need and filter them in the code. If you have to do this it might be worth using an initial predicate like
x => x.Address1.Contains(foo[0]) || x.Address2.Contains(foo[0])to limit the number of objects you get back. I leave it to you to come up with a better initial predicate than this.