Filter records using Linq on an Enum type -
i'm hoping simple solution. have field (presstype) in table (stocks) seed populated using enum. table stores data integer. when want query data via linq gives me issues. can filter other fields in table using format on enum populated field says
the "==" operator cannot applied operands of type "models.presstype" , "string".
any give appreciated, thanks.
var test = db.stocks.where(x => x.presstype == myvalue);
there nothing wrong linq. problem myvalue
of type string
. need convert string enum first.
string myvalue = somecontrol.text; models.presstype myvalueasenum = (models.presstype) enum.parse(typeof(models.presstype), myvalue); iqueryable<stock> test = db.stocks.where(x => x.presstype == myvalueasenum);
Comments
Post a Comment