I'm trying to query my ProductiveUnits table against an array of values from the AspNetUsersGroupMaps table. A AspNetUserID can be linked to many UserGroupID's on the AspNetUsersGroupMaps table. I only want the list of ProductiveUnits returned where the ProductiveUnit.UserGroupID = AspNetUsersGroupMaps.UserGroupID as following:
public ActionResult ProductiveUnits_Read([DataSourceRequest]DataSourceRequest request)
{
var UserID = User.Identity.GetUserId();
int[] selectedIds = db.AspNetUsersGroupMaps.Where(t => t.AspNetUserID == UserID).Select(x => x.UserGroupID).ToArray();
IQueryable<ProductiveUnit> productiveunits = db.ProductiveUnits.Where(p => p.UserGroupID.Equals(selectedIds));
DataSourceResult result = productiveunits.ToDataSourceResult(request, productiveUnit => new {
ProdUnitID = productiveUnit.ProdUnitID,
PU_Text = productiveUnit.PU_Text,
PUGroup = productiveUnit.PUGroup,
SerialNo = productiveUnit.SerialNo,
ExtSysPU_ID = productiveUnit.ExtSysPU_ID,
ProdUnitNo = productiveUnit.ProdUnitNo,
CompanyID = productiveUnit.CompanyID,
Criticality = productiveUnit.Criticality,
YearModel = productiveUnit.YearModel,
CostCentreID = productiveUnit.CostCentreID,
CurrencyID = productiveUnit.CurrencyID,
StartupDate = productiveUnit.StartupDate,
UserGroupID = productiveUnit.UserGroupID,
});
return Json(result);
}
I get the following error:
Cannot compare elements of type 'System.Int32[]'. Only primitive types, enumeration types and entity types are supported.'
My AspNetUsersGroupMap Model:
public partial class AspNetUsersGroupMap
{
public int ID { get; set; }
public string AspNetUserID { get; set; }
public int UserGroupID { get; set; }
public virtual UserGroup UserGroup { get; set; }
public virtual AspNetUser AspNetUser { get; set; }
}
Please assist