That's basically what I was attempting in my 3rd option, but I can't seem to get it to work. I'm getting an exception when I try to send the SerializedExpression to our server.
var p1 = PredicateBuilder.Make<Requirement>(i => i.FTN.Contains("345")); var q = ASTEM.Requirements.Where(p1); var expr = SerializedExpression.ToSerializedExpression(q.Expression);
// At this point we send expr to our web service method.
|
'Type 'IdeaBlade.Core.TypeWrapper' with data contract name 'TypeWrapper:http://ideablade.com/Core' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
So to eliminate our call to our web service method being the issue, I tried:
var p1 = PredicateBuilder.Make<Requirement>(i => i.FTN.Contains("345")); var q = ASTEM.Requirements.Where(p1); var expr = SerializedExpression.ToSerializedExpression(q.Expression);
var serializer = new DataContractSerializer(expr.GetType());
byte[] data = null; using (var stream = new MemoryStream()) { serializer.WriteObject(stream, expr); stream.Seek(0, SeekOrigin.Begin); data = stream.GetBuffer(); }
|
Which results in the same exception when calling serializer.WriteObject().
If I add TypeWrapper as a known type by doing the following, I receive the same exception for a different type:
var knownTypes = new List<Type>() { typeof(IdeaBlade.Core.TypeWrapper) }:
var serializer = new DataContractSerializer(expr.GetType(), knownTypes);
|
Type 'IdeaBlade.EntityModel.EntityQueryProxy`1[[AST.ObjectModel.Requirement, AST.ObjectModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=dba36b71950587e5]]' with data contract name 'EntityQueryProxyOfRequirement_PBxM0UCr:http://ideablade.com/EntityModel' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
And if I add expr.GetType() to the known types list, it doesn't appear to help at all. I continue to get that same exception.
var knownTypes = new List<Type>() { typeof(IdeaBlade.Core.TypeWrapper), expr.GetType() }:
var serializer = new DataContractSerializer(expr.GetType(), knownTypes);
|
Type 'IdeaBlade.EntityModel.EntityQueryProxy`1[[AST.ObjectModel.Requirement, AST.ObjectModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=dba36b71950587e5]]' with data contract name 'EntityQueryProxyOfRequirement_PBxM0UCr:http://ideablade.com/EntityModel' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.