0

I can't seem to find any good examples but what is the best way to do a query like this

tbl.Query(SELECT * FROM PRODUCTS WHERE ProductId IN (@Ids)", idlist)

I see that Dapper ORM, you can just put in a list and it knows what to do. Can you do this with Massive or do I have to build out the parameters like @0,@1,@2 and turn the list into an array idList.ToArray()?

user204588
  • 1,613
  • 4
  • 31
  • 50

1 Answers1

0

It doesn't look like this is possible. When I tried (ids was an array in my case) I got the error:

No mapping exists from object type System.Int32[] to a known managed provider native type.

Which tends to make me think that Massive is largely letting the underlying SQL provider deal with the parameterization of the query. So yes, you are going to have to do build the parameters like you said. You could do something like this:

productTable.Query(string.Format("SELECT * FROM PRODUCTS WHERE ProductId IN ({0})",
    string.Join(",", ids.Select((id, ix) => "@" + ix).ToArray())),
    ids.Cast<object>().ToArray());
nick_w
  • 14,758
  • 3
  • 51
  • 71