如何格式化linq表达式中的字符串?

Kev*_*vin 7 c# 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("###-###-#### ####") + ")";
Run Code Online (Sandbox Code Playgroud)

这是对我的实体框架的调用.我从数据库中返回一个电话号码.我试图在给定的格式字符串中格式化它.不幸的是,当我运行它时,我收到以下错误:

LINQ to Entities does not recognize the method 'System.String ToString(System.String)' method, and this method cannot be translated into a store expression.
Run Code Online (Sandbox Code Playgroud)

所以我的问题是如何将此数据库对象作为格式化字符串返回?

谢谢!

Jon*_*eet 21

我会在数据库中执行查询,但在本地格式化:

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("###-###-#### ####") + ")");
Run Code Online (Sandbox Code Playgroud)