问题描述
我尝试创建一个LINQ在nopCommerce 3.0连接查询。我在LINQ连接两个表,写
I try to create a linq join query in the nopCommerce 3.0. i join two table in linq and write
在code成功。但在Visual Studio intellicence节目,如
the code successfully. but the visual studio intellicence shows the error like
的语句体一个lambda前pression不能转换为前pression树
请参见下面的
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前pression。它有一个说法的身体。与语句体一个lambda前pression不能转换为前pression树。但加入
需要一个前pression树EF使用。你应该尝试与没有一个身体像一个lambda前pression更换您是否有什么:
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前pression不能转换为nopCommerce一个前pression树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!