Using the ASP.NET Web-Api, I have the following POST setup in my controller. When posting to it from Fiddler, I get the error message:
The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities.
…when it gets to the var auth = dba.ApiMembers… line
// POST api/Avail
[BasicAuthentication]
public HttpResponseMessage PostAvail(Avail[] avail)
{
if (ModelState.IsValid)
{
// Check if authorised
var auth = dba.ApiMembers.Where(a => a.hotel_id ==
avail[0].HID && a.UserName == User.Identity.Name)
.FirstOrDefault();
Can anyone see anything wrong with this line?
LINQ2SQL queries run in database, and it’s not possible to translate
User.Identity.Nameandavail[0]into database commands. You should initialize those values as parameters and pass simple types to LINQ query.