c# - Query populate string based on dictionary lookup -


so have following query

        iqueryable<feedback> query = db.feedbacks;         var result = query             .select(s => new feedbackviewmodel             {                 businessid = s.account.businesses.firstordefault().businessid,                 hiresuccess = s.hiresuccess.value,                 useagain = s.useagain.value,                 suggestions = s.suggestions,                 employees = numbergroups[s.numemployees.value]             });         return result; 

and im getting error

additional information: linq entities not recognize method 'system.string get_item(int32)' method, , method cannot translated store expression.

due attempting set employees string dictionary lookup, dictionary looks this.

    public static dictionary<int, string> numbergroups = new dictionary<int, string>()     {         { 0, "none" },         { 9, "1 9" },         { 19, "10 19" },         { 49, "20 49" },         { 100, "50 100" }     }; 

the feedbackviewmodel looks this

public class feedbackviewmodel {     public int businessid { get; set; }     public bool hiresuccess { get; set; }     public bool useagain { get; set; }     public string suggestions { get; set; }     public string employees { get; set; } } 

what doing wrong?

i think trying query database. linq sql not support methods numbergroups[s.numemployees.value].

you may consider doing this.

          var query = db.feedbacks.select(f = > new                 {                     businessid = s.account.businesses.firstordefault().businessid,                     hiresuccess = s.hiresuccess.value,                     useagain = s.useagain.value,                     suggestions = s.suggestions.value,                     numemployees = s.numemployees.value                 }).tolist();             var result = query               .select(s => new feedbackviewmodel                 {                     businessid = s.businessid,                     hiresuccess = s.hiresuccess,                     useagain = s.useagain,                     suggestions = s.suggestions,                     employees = numbergroups[s.numemployees]                 }).tolist(); 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -