-1

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();
James123
  • 11,184
  • 66
  • 189
  • 343

2 Answers2

3

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();
scott.korin
  • 2,537
  • 2
  • 23
  • 36
0
    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));
  • Can you explain how this answers the question? – Ḟḹáḿíṅḡ Ⱬỏḿƀíé Apr 10 '17 at 13:15
  • DBContect does not recognizes some of in built functions such as Conversion Functions etc during execution.So execute linq query as it is with DBContext. Finally update list through loop and ForEach in list based loop which updates every pointed fields. Because It is not connect and related to DBContext every function will work here. :) .. I am using same and working fine :) – Minhajul Islam Apr 11 '17 at 13:45