LINQ to Entities does not recognize the method 'System.String ToBase64String(Byte[])' method,

家住魔仙堡 提交于 2020-01-07 09:28:11

问题


LINQ to Entities does not recognize the method 'System.String ToBase64String(Byte[])' method, and this method cannot be translated into a store expression.

 var activityList = (from item in committeeMemberList
                let committee = db.Committee.FirstOrDefault(x => x.Committee_Id == item.Committee_Id)
                let contact = db.Contacts.FirstOrDefault(x => x.Contact_Id == item.Contact_Id)
                select new Activity
                {
                   Id = Convert.ToBase64String(item.Committee_Member_SPE_Id), 
                   Name = committee.Committee_Name, 
                   ...
                   ...

                  }).ToList();

回答1:


Change your LINQ so that your original statement returns a list of anonymous objects, and then select on THAT list and use the ToBase64String function:

var activityList = 
            (from item in
                (from member in committeeMemberList
                let committee = db.Committee.FirstOrDefault(x => x.Committee_Id == item.Committee_Id)
                let contact = db.Contacts.FirstOrDefault(x => x.Contact_Id == item.Contact_Id)
                select new
                {
                   Id = member.Committee_Member_SPE_Id, 
                   Name = committee.Committee_Name, 
                   ...
                   ...
                 }).ToList())
            select new Activity
            {
               Id = Convert.ToBase64String(item.Id), 
               Name = committee.Committee_Name, 
               ...
               ...

            }).ToList();



回答2:


    var activityList = 
                (from item in
                    (from member in committeeMemberList
                    let committee = db.Committee.FirstOrDefault(x => x.Committee_Id == item.Committee_Id)
                    let contact = db.Contacts.FirstOrDefault(x => x.Contact_Id == item.Contact_Id)
                    select new
                    {
                       Id = member.Committee_Member_SPE_Id, 
                       Name = committee.Committee_Name, 
                       ...
                       ...
                     }).ToList());
//After Collecting information just update current value to base4string using following Syntax

activityList.ForEach(s=>s.id=(s.id==null?"noimage":Convert.ToBase4String(s.id));


来源:https://stackoverflow.com/questions/15392425/linq-to-entities-does-not-recognize-the-method-system-string-tobase64stringbyt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!