-1
var messages = (from sms in
                (from m in rv.tbl_sms_messages
                where m.idtbl_user == ids.id
                where m.sms_date >= days.days7
                orderby m.sms_date descending
                select m)
                .Take(15)
                .AsEnumerable()
                    select new last10msgs 
                    { 
                        dat = SqlFunctions.StringConvert((double)SqlFunctions.DatePart("dd",sms.sms_date)) + " " 
                                + SqlFunctions.DateName("mm", sms.sms_date), message = sms.message 
                    }).AsEnumerable();

Got the error after updating from EF4 TO EF6+:

This function can only be invoked from LINQ to Entities.

Selim Yildiz
  • 5,254
  • 6
  • 18
  • 28
FLAMER283
  • 3
  • 4

1 Answers1

1

The problem is you have already done the DB operation when you try to use SqlFunctions. These functions have to be placed before running your query and storing the result into objects. After calling AsEnumerable your query is done. So the short answer is to move the logic which contains these functions to the query that runs against the DB (before the Take clause)

Siavash Rostami
  • 1,883
  • 4
  • 17
  • 31