Given the following code
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("###-###-#### ####") + ")";
This is a call to my entity framework. I am returning a phone number from the database. I am trying to format it in the given format string. Unfortunately, when I run this, I receive the following error:
LINQ to Entities does not recognize the method 'System.String ToString(System.String)' method, and this method cannot be translated into a store expression.
So my question is how do I return this database object as a formatted string?
Thanks!
I would perform the querying in the database, but the formatting locally:
var customers = db.Customers
.Where(c => c.CstCompanyName.Contains(prefixText))
.Select(c => new { c.CstCompanyName, c.CstPhone })
.AsEnumerable() // Switch to in-process
.Select(c => c.CstCompanyName +
" (Phone: " +
Convert.ToInt64(Customers.CstPhone)
.ToString("###-###-#### ####") + ")");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With