下面的代码会产生错误:
LINQ to Entities 无法识别方法
System.String GenerateSubscriptionButton(Int32)
method,并且此方法无法转换为存储表达式。
如何在 LINQ to Entities 中创建正确的自定义方法?
var model = _serviceRepository.GetProducts().Select(p => new ProductModel
{
Id = p.Id,
Name = p.Name,
Credits = p.Credits,
Months = p.Months,
Price = p.Price,
PayPalButton = GenerateSubscriptionButton(p.Id)
});
private string GenerateSubscriptionButton(int id)
{
return new PaymentProcessor.PayPalProcessor().CreateSubscriptionButton(id);
}