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

StackOverflow https://stackoverflow.com/questions/15392425

  •  23-03-2022
  •  | 
  •  

Question

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();
Was it helpful?

Solution

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();

OTHER TIPS

    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));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top