I do have following model in my project
public class DocModel { [Id] public int Id { get; set; } public string DocName { get; set; } public double Rating { get; set; } }
And, in the Find index, there is a object corresponding to above model
{"Id$$number": 719,"DocName$$string": "My Doc","Rating$$number": 0 }
But, when I try to execute following query
var docs = SearchClient.Instance.Search<DocModel>() .Filter(x => x.Id.Match(719)) .Select(x => new { DocRating = x.Rating}).GetResult();
It will end-up with an exception
EPiServer.Find.ProjectionException was unhandled HResult=-2146232832 Message=An exception of type ArgumentException was thrown while projecting field Rating$$number. Source=EPiServer.Find StackTrace: at EPiServer.Find.ProjectionHelper.ReplaceExpressionWithConstantFromField(Dictionary`2 args, Expression expression) at EPiServer.Find.ProjectionHelper.<>c__DisplayClass35.<ReplaceMemberAssignmentsWithFieldValues>b__34(Expression expression) at EPiServer.Find.Helpers.Linq.ExpressionReplacer`1.Visit(Expression expression) at EPiServer.Find.Helpers.Linq.ExpressionVisitor.VisitExpressionList(ReadOnlyCollection`1 original) at EPiServer.Find.Helpers.Linq.ExpressionVisitor.VisitNew(NewExpression nex) at EPiServer.Find.Helpers.Linq.ExpressionVisitor.Visit(Expression exp) at EPiServer.Find.Helpers.Linq.ExpressionReplacer`1.Visit(Expression expression) at EPiServer.Find.Helpers.Linq.ExpressionReplacer`1.Replace(Expression expression, Func`2 predicate, Func`2 replaceWith) at EPiServer.Find.Helpers.Linq.ExpressionExtensions.Replace[TExpression](Expression expression, Func`2 predicate, Func`2 replaceWith) at EPiServer.Find.ProjectionHelper.ReplaceMemberAssignmentsWithFieldValues(Expression selector, Dictionary`2 args) at EPiServer.Find.ProjectionHelper.GetMappedSearchResultItem[TResult](SearchRequestBody requestBody, SearchHit`1 searchHit) at EPiServer.Find.ProjectionHelper.GetMappedResult[TResult](SearchRequestBody requestBody, SearchResults`1 jsonResult) at EPiServer.Find.SearchExtensions.GetProjectedResult[TResult](ISearch`1 search, SearchContext context) at EPiServer.Find.SearchExtensions.GetResult[TResult](ISearch`1 search) at FindTestApp.Program.Main(String[] args) in e:\FindTestApp\FindTestApp\FindTestApp\Program.cs:line 43 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: System.ArgumentException HResult=-2147024809 Message=Argument types do not match Source=System.Core StackTrace: at System.Linq.Expressions.Expression.Constant(Object value, Type type) at EPiServer.Find.ProjectionHelper.ReplaceExpressionWithConstantFromField(Dictionary`2 args, Expression expression) InnerException:
So, what is wrong with my query and how do I fix it ?