Kristen Jones
asked on
C# LINQ Syntax help with Where clause
I have this code
IT works fine Except I want to pass the woid to a where clause in the results. So I added this line
.where(c.WOID==woid)
It is failing with unknown method "where of string" I am sure it is something simple stupid but after an hour of trying everything I am turning to the experts.
public ActionResult GRIDPRINTS_Read(int woid, [DataSourceRequest]DataSourceRequest request)
{
IQueryable<GRIDPRINTS> gridprints = db.GRIDPRINTS;
DataSourceResult result = gridprints.ToDataSourceResult(request, c => new GRIDPRINTS
{
WOID = c.WOID,
GRIDPRTID = c.GRIDPRTID,
GRIDID = c.GRIDID,
MAPNAME = c.MAPNAME,
SCALE = c.SCALE,
PAGENUMBER = c.PAGENUMBER,
ERRORS = c.ERRORS,
STATUS = c.STATUS,
NOTIFICATION = c.NOTIFICATION
});
return Json(result, JsonRequestBehavior.AllowGet);
}
IT works fine Except I want to pass the woid to a where clause in the results. So I added this line
.where(c.WOID==woid)
public ActionResult GRIDPRINTS_Read(int woid, [DataSourceRequest]DataSourceRequest request)
{
IQueryable<GRIDPRINTS> gridprints = db.GRIDPRINTS;
DataSourceResult result = gridprints.ToDataSourceResult(request, c => new GRIDPRINTS
{
WOID = c.WOID,
GRIDPRTID = c.GRIDPRTID,
GRIDID = c.GRIDID,
MAPNAME = c.MAPNAME,
SCALE = c.SCALE,
PAGENUMBER = c.PAGENUMBER,
ERRORS = c.ERRORS,
STATUS = c.STATUS,
NOTIFICATION = c.NOTIFICATION
.where(c.WOID==woid)
});
return Json(result, JsonRequestBehavior.AllowGet);
}
It is failing with unknown method "where of string" I am sure it is something simple stupid but after an hour of trying everything I am turning to the experts.
ASKER
I thought that too but it errors on the
Unknown entity which I think makes sense, since it is out of the ToDatasourceResult(c=>...)
c.
Unknown entity which I think makes sense, since it is out of the ToDatasourceResult(c=>...)
It errors because you are performing a new task, you have to resupply an identifier for the anonymous object; e.g. -
-saige-
}).Where(c => c.WOID==woid);
Complete code -
public ActionResult GRIDPRINTS_Read(int woid, [DataSourceRequest]DataSourceRequest request)
{
IQueryable<GRIDPRINTS> gridprints = db.GRIDPRINTS;
DataSourceResult result = gridprints.ToDataSourceResult(request, c => new GRIDPRINTS
{
WOID = c.WOID,
GRIDPRTID = c.GRIDPRTID,
GRIDID = c.GRIDID,
MAPNAME = c.MAPNAME,
SCALE = c.SCALE,
PAGENUMBER = c.PAGENUMBER,
ERRORS = c.ERRORS,
STATUS = c.STATUS,
NOTIFICATION = c.NOTIFICATION
}).Where(c => c.WOID == woid);
return Json(result, JsonRequestBehavior.AllowGet);
}
-saige-
ASKER
I tried that too, but gives 3 errors:
Error 11 Instance argument: cannot convert from 'Kendo.Mvc.UI.DataSourceRe sult' to 'System.Linq.IQueryable'
Error 12 'Kendo.Mvc.UI.DataSourceRe sult' does not contain a definition for 'Where' and the best extension method overload 'Kendo.Mvc.Extensions.Quer yableExten sions.Wher e(System.L inq.IQuery able, System.Linq.Expressions.Ex pression)' has some invalid arguments
Error 13 Argument 2: cannot convert from 'lambda expression' to 'System.Linq.Expressions.E xpression'
Error 11 Instance argument: cannot convert from 'Kendo.Mvc.UI.DataSourceRe
Error 12 'Kendo.Mvc.UI.DataSourceRe
Error 13 Argument 2: cannot convert from 'lambda expression' to 'System.Linq.Expressions.E
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ah! perfect thanks so much!
Open in new window