Method 'System.String Format(System.String, System.Object, System.Object, System.Object)' has no supported translation to SQL


Method 'System.String Format(System.String, System.Object, System.Object, System.Object)' has no supported translation to SQL.

Once I was working on the Linq query and found the above error message . 
Actually i was inserting some data into the database by Linq query and  this was the code

 foreach (var rep in (from rep in db.DO_TR
                                                 join ab in db.DO_TA on rep.TeacherAbsenceID equals ab.Id
                                                 join tt in db.Archive_TT on string.Format("{0}{1} ({2})", rep.RollClassCode,                                                        rep.Block, rep.Row) equals tt.GroupRowID
                                                 join clss in db.Archive_Classes on tt.ClassID equals clss.ID
                                                 join rc in db.Archive_RollClasses on tt.RollClassID equals rc.ID
                                                 where (clss.Code == item.ClassCode) && (rc.Code == item.RollClassCode) && (ab.CalendarID == item.CalendarID)
                                                 select new { rep, ab }))
                            {
                                
                            }

We can fix this issue just removing the string.Format , and just adding the value like

foreach (var rep in (from rep in db.DO_TR
                                             join ab in db.DO_TA on  rep.TeacherAbsenceID equals ab.Id
                                             join tt in db.Archive_TT on rep.RollClassCode + " " + rep.Block + "(" +                                                                rep.Row + ")" equals tt.GroupRowID
                                             join clss in db.Archive_Classes on tt.ClassID equals clss.ID
                                             join rc in db.Archive_RollClasses on tt.RollClassID equals rc.ID
                                             where (clss.Code == item.ClassCode) && (rc.Code == item.RollClassCode) && (                                               (ab.CalendarID == item.CalendarID)
                                             select new { rep, ab }))
                        {
                           
                        }


Thanks . Let me know if you have any issue .

Comments

Popular posts from this blog

The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.

The transaction is aborted or Failure while attempting to promote transaction.

Unable to load one or more breakpoints in Visual studio.