Re: [RavenDB] Error when trying to use Enum in a .In Where clause

43 views
Skip to first unread message

Oren Eini (Ayende Rahien)

unread,
Apr 29, 2022, 2:15:10 AM4/29/22
to rav...@googlegroups.com
var result = await Query<InvoiceWorkflow>()
.Where(x => x.WorkflowStage.In  = WorkflowStage.Error)
.GroupBy(x => x.WorkflowStage)
.Select(x=>new { x.WorkflowStage })
.ToListAsync();

That should fix it

On Thu, Apr 28, 2022 at 9:00 PM Stephen <ssaa...@gmail.com> wrote:
We're using RavenDB 5.3 both client and server and we have the following code.

using Raven.Client.Documents.Linq;

var result = await Query<InvoiceWorkflow>()
.Where(x => x.WorkflowStage.In(WorkflowStage.Error, WorkflowStage.NewSupplier))
.GroupBy(x => x.WorkflowStage)
.ToListAsync();

and when I run it I get this error:

System.InvalidOperationException: Could not convert document  to entity of type System.Linq.IGrouping`2[Domain.InvoiceWorkflow.WorkflowStage,Domain.InvoiceWorkflow.InvoiceWorkflow]
 ---> Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Linq.IGrouping`2[Domain.InvoiceWorkflow.WorkflowStage,Domain.InvoiceWorkflow.InvoiceWorkflow]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correc
tly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be ad
ded to the type to force it to deserialize from a JSON object.

But if I just use:

var result = await Query<InvoiceWorkflow>()
.Where(x => x.WorkflowStage.In  = WorkflowStage.Error)
.GroupBy(x => x.WorkflowStage)
.ToListAsync();

everything works.

Workflow stage is defined as:

public enum WorkflowStage
{
SupplierEntry,
NewSupplier,
PictureCleanup,
ItemCodeAndPrice,
PackSize,
Approved,
PictureIssue,
SalesUom,
Error,
DevProblem,
NotProcessable
}

This seems really simple, but so far I haven't been able to get this to work.

--
You received this message because you are subscribed to the Google Groups "RavenDB - an awesome database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ravendb/25adf937-bee7-49e8-af4c-5674ad2eb01an%40googlegroups.com.


--
Oren Eini
CEO   /   Hibernating Rhinos LTD
Skype:  ayenderahien
Support:  sup...@ravendb.net
  
Reply all
Reply to author
Forward
0 new messages