LINQ to Entities does not recognize the method 'Boolean HasFlag(System.Enum)' method, and this method cannot be translated into a store expression -
i have service:
//seroiunoiweucroewr ///wercewrwerwerwer //wcererewrwerwer public list<userrolecontract> getrolepagesbyuserid(long plnguserid, displaytype displaytype) { list<userrolecontract> result = new list<userrolecontract>(); using (citicallentities context = new citicallentities()) { try { //var displaylist = utility.getenumdescriptions(typeof(displaytype)).tolist(); //var selectvalue = displaylist.where(i => i.key == (byte) displaytype.windows).firstordefault(); result = (from ouser in context.user join ouserrole in context.userrole on ouser.id equals ouserrole.userid join orolerightspage in context.rolerightspage.where(i => i.isactive == true) on ouserrole.roleid equals orolerightspage.roleid join oapplicationpage in context.applicationpage.where(i => i.isactive == true) on orolerightspage.pageid equals oapplicationpage.id join orole in context.role on ouserrole.roleid equals orole.id join oemployee in context.employee on ouser.employeeid equals oemployee.id join osection in context.section on oemployee.sectionid equals osection.id ouser.isactive == true && ouser.id == plnguserid && orole.isactive == true && (((displaytype)orolerightspage.displaytype).hasflag(displaytype)) //am getting error in has flag // having 3 display type web, windows , // how overcome select new userrolecontract { userid = ouser.id, roleid = orole.id, rolename = orole.rolename, pageid = oapplicationpage.id, pagename = oapplicationpage.pagename, isopsctrl = orole.isopsctrl, isopsctrlfor = orole.opsctrlfor, sectionid = osection.id, displaytype = orolerightspage.displaytype, }).distinct().tolist(); } catch (exception exception) { handleexpcetion(exception); //throw new citicallexception(exception.message); } } return result; }
i getting linq error in has flag conversion, how overcome problem?
you geeting error because hasflag method not paresent in database i.e. might part of language or local function in code not present in database.
so when query translated found method not available , reason getting error.
one solution avoid error
brind data databae
than filter data, i.e. apply hasflag method of it.
but bring data , might decrease performance.
example
remove line (((displaytype)orolerightspage.displaytype).hasflag(displaytype)
query
var list = querieddata //first fetch data without hasflag condition/method .asenumerable() // rest of query in-process .where(orolerightspage=> ((displaytype)orolerightspage.displaytype).hasflag(displaytype))//apply condition here once fetching done .tolist();
Comments
Post a Comment