I have a class with a property that contains serialized data in json format:
public class MyObject
{
public string SerializedData
{
get
{
...
}
set
{
...
}
}
}
The object is a property on a entity framework database object:
public class MyRecord
{
public int Id { get; set; }
public MyObject Item { get; set; }
}
I'm now trying to write a LINQ statement to check if the serialized string contains my search text. I'm building the LINQ statement dynamically:
var predicate = PredicateBuilder.New<TEntity>();
var param = Expression.Parameter(typeof(TEntity), typeof(TEntity).Name);
Expression property = Expression.Property(param, type.Name);
Expression contains = Expression.Call(
property, "Contains",
null,
new[] { Expression.Constant("test") });
predicate.Or(Expression.Lambda<Func<TEntity, bool>>(contains, param));
My object doesn't contain the "Contains" method so I add one:
public class MyObject
{
...
public bool Contains(string value)
{
return true;
}
}
When my query runs I get the following error:
LINQ to Entities does not recognize the method 'Boolean Contains(System.String)' method, and this method cannot be translated into a store expression.
I not sure if I'm even approaching this in the correct way?
Can anyone help please?
Thanks