Dato il seguente codiceCome formattare una stringa in un'espressione linq?
IQueryable<string> customers =
from Customers in db.Customers
where Customers.CstCompanyName.Contains(prefixText) && Customers.CstInactive == false
select Customers.CstCompanyName + " (Phone: " + Convert.ToInt64(Customers.CstPhone).ToString("###-###-#### ####") + ")";
Questa è una chiamata al mio quadro entità. Sto restituendo un numero di telefono dal database. Sto provando a formattarlo nella stringa di formato indicata. Purtroppo, quando ho eseguito questo, ricevo il seguente errore:
LINQ to Entities does not recognize the method 'System.String ToString(System.String)' method, and this method cannot be translated into a store expression.
Quindi la mia domanda è: come faccio a restituire l'oggetto di database come una stringa formattata?
Grazie!
Avete bisogno che il risultato sia un 'IQueryable'? Non puoi semplicemente ottenere un 'IEnumerable' usando 'var customers = ...'? –
no. Avere il database a gestire i dati; avere un accordo sulla presentazione del codice con la presentazione. – AakashM
Alla fine, viene restituito come una stringa [], quindi qualsiasi cosa lo compia. Quello che sto facendo attualmente è string [] cst = customers.ToArray(); Quindi non sono abbastanza sicuro se deve essere IQueryable. – Kevin