Estoy intentado compilar mi codigo pero me sale el siguiente error
Excepción producida: 'System.NotSupportedException' en EntityFramework.SqlServer.dll
Se produjo una excepción de tipo 'System.NotSupportedException' en EntityFramework.SqlServer.dll pero no se controló en el código del usuario
LINQ to Entities does not recognize the method 'System.String PadLeft(Int32, Char)' method, and this method cannot be translated into a store expression.
Trato de obtener la informacion desde la base de datos para ser procesados y presentados en un Datatable, estoy usando LINQ y Entity Framework
IQueryable<TicketsResult> query;
if (string.Equals(Session["tipo"].ToString(), "admin", StringComparison.OrdinalIgnoreCase) ||
string.Equals(Session["tipo"].ToString(), "mesa", StringComparison.OrdinalIgnoreCase))
{
query = TicketListModel.ConsultTicketListAll(db);
}
else
{
query = TicketListModel.ConsultTicketListTech(Session["matricula"].ToString(), db);
}
var totalCount = query.Count();
Esta es la Query donde obtengo la informacion desde la BD
public static IQueryable<TicketsResult> ConsultTicketListAll(dbGoldenTicket db)
{
return from tblTicket in db.TK_HD_TICKETS
join tblRecord in db.TK_DT_RECORDS on tblTicket.TK_HD_TICKETS_ID equals tblRecord.TK_HD_TICKETS_ID
join tblServices in db.TK_CT_SERVICES on tblRecord.TK_CT_SERVICES_ID equals tblServices.TK_CT_SERVICES_ID
join tblStatus in db.TK_CT_STATUS on tblRecord.TK_CT_STATUS_ID equals tblStatus.TK_CT_STATUS_ID
where tblRecord.TK_DT_RECORDS_ID == (
from tblTicketAux in db.TK_HD_TICKETS
join tblRecordAux in db.TK_DT_RECORDS on tblTicketAux.TK_HD_TICKETS_ID equals tblRecordAux.TK_HD_TICKETS_ID
where tblTicket.TK_HD_TICKETS_ID == tblTicketAux.TK_HD_TICKETS_ID
select tblRecordAux.TK_DT_RECORDS_ID
).Max()
select new TicketsResult()
{
TicketCode = tblTicket.TK_CT_AREAS_ID + "-" + tblTicket.CREATE_DATE.Year +
tblTicket.CREATE_DATE.Month.ToString().PadLeft(2, '0') +
tblTicket.CREATE_DATE.Day.ToString().PadLeft(2, '0') +
tblTicket.SEQUENCE_NUMBER.ToString().PadLeft(4, '0'),
TicketAplicant = tblTicket.CUSTOMER_FULLNAME,
TicketSubjet = tblTicket.TITLE,
TicketStatus = tblStatus.NAME,
TicketService = tblServices.NAME,
TicketEmployee = tblRecord.TK_BT_EMPLOYEES_ID
};
}
String
no es soportada paraIQueryable
, mejor utilizaDbFunctions
, aquí la documentación de esta clase: DbFunctionsDbFunctions.Left()
es el equivalente aPadLeft()
compatible. Aquí la documentación