In Swagger I insert some values and I want to pass an array of strings, containing those values, to Linq. (the ids are strings in this case). If I pass a simple string, not an array, it works to insert one value. But I need to pass an array of values.
Here's a link built by the API when trying to insert 2 values (it looks weird for an array): http://localhost:port/api/Members?ids=97882831302&ids=97882831308
The problem is that the array shows NULL instead of the values inserted. And I get the following error:
"ExceptionMessage": "Unable to create a null constant value of type
'System.String[]'. Only entity types, enumeration types or primitive
types are supported in this context."
public class MembersController : ApiController
{
public HttpResponseMessage GetAllMembersByIdentifiers(string[] ids) {
using (sampleEntities entities = new sampleEntities()){
var numbers = entities.tblmembers
.Where(p => ids.Contains(p.identify) ).ToList();
if (numbers != null)
{
return Request.CreateResponse(HttpStatusCode.OK, numbers);
}
else
{
return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Member with id: " + ids + " not found");
}
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…