具有语句正文的lambda表达式无法转换为nopCommerce中的表达式树 [英] A lambda expression with a statement body cannot be converted to an expression tree in nopCommerce
问题描述
我尝试在nopCommerce 3.0中创建一个linq连接查询。我在linq中加入两个表,并成功写入
I try to create a linq join query in the nopCommerce 3.0. i join two table in linq and write
代码。但是visual studio intellicence显示错误,如
the code successfully. but the visual studio intellicence shows the error like
具有语句正文的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表达式。它有一个声明机构。具有语句正文的lambda表达式无法转换为表达式树。但是加入
需要使用表达式树与EF配合使用。你应该尝试用一个没有body的lambda表达式来替换你所拥有的东西,比如:
The error message is exactly what it says. You have a lambda expression. It has a statement body. A lambda expression with a statement body can not be converted to an expression tree. But Join
requires an expression tree to use with EF. You should try replacing what you have with a lambda expression that doesn't have a body like:
(cev, c) => new CustomerEventRolesModel {
Id = cev.Id,
CustomerId = c.Id
}
等等。
顺便说一句,
ContactName = c.GetAttribute<string>(SystemCustomerAttributeNames.FirstName)
将无法使用EF 。期。你更好地想出别的东西。
will NOT work with EF. Period. You better figure something else out.
这篇关于具有语句正文的lambda表达式无法转换为nopCommerce中的表达式树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!