【发布时间】:2013-08-08 08:58:19
【问题描述】:
我尝试在 nopCommerce 3.0 中创建一个 linq 连接查询。我在 linq 中加入两个表并写入
代码成功。但视觉工作室智能显示错误,如
带有语句体的 lambda 表达式不能转换为表达式树
请看下面我的代码
var roles = _customerEventRoleRepository.Table.Where(c => c.EventId == selevent)
.Join
(
_customerRepository.Table,
cev => cev.CustomerId, c => c.Id,
(cev, c) =>
{
var cust = new CustomerEventRolesModel();
cust.Id = cev.Id;
cust.CustomerId = c.Id;
cust.Customer = c.Email;
cust.ContactName = c.GetAttribute<string>(SystemCustomerAttributeNames.FirstName);
cust.CompanyName = c.GetAttribute<string>(SystemCustomerAttributeNames.Company);
cust.Speaker = cev.IsSpeaker;
cust.Sponsor = cev.IsSponser;
return cust;
}
).OrderBy(cev => cev.Customer).ToList();
但错误显示
请帮忙
【问题讨论】:
-
你的 lambda 是一个函数。此函数无法转换为 SQL。你需要找到另一种方法来做你正在做的事情。
-
感谢您的宝贵回复。此处查询结果中需要 ContactName 和 CompanyName。
标签: c# asp.net-mvc-3 linq entity-framework-4 nopcommerce