Use Contains in an integer field in C # with lambda or LINQ

3

I have the following expression:

 query = query.Where(x => x.MeuCampoInteiro.ToString().Contains(filter));

But an exception is occurring:

 System.NotSupportedException: 'The expression [10008].MeuCampoInteiro.ToString() is not supported.'

Is there any way to do ToString() or Contains() in an integer field in the expression lambda ?

    
asked by anonymous 27.09.2017 / 16:43

1 answer

2

Try:

query = query.Where(x => Convert.ToString(x.MeuCampoInteiro).Contains(filter));

If it does not, use:

query = query.Where(x => SqlFunctions.StringConvert(x.MeuCampoInteiro).Contains(filter));

Documentation .

The title question does not make much sense .

    
27.09.2017 / 17:32