带有语句体的lambda表达式无法转换为nopCommerce 中的表达式树
我尝试在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(SystemCustomerAttributeNames.FirstName); cust.CompanyName = c.GetAttribute(SystemCustomerAttributeNames.Company); cust.Speaker = cev.IsSpeaker; cust.Sponsor = cev.IsSponser; return cust; } ).OrderBy(cev => cev.Customer).ToList();
但错误显示
请帮忙
错误消息正是它所说的。 你有一个lambda表达式。 它有一个声明正文。 具有语句主体的lambda表达式无法转换为表达式树。 但是Join
需要一个表达树来与EF一起使用。 您应该尝试使用没有正文的lambda表达式替换您拥有的内容:
(cev, c) => new CustomerEventRolesModel { Id = cev.Id, CustomerId = c.Id }
等等。
顺便说说,
ContactName = c.GetAttribute(SystemCustomerAttributeNames.FirstName)
不适用于EF。 期。 你最好找出别的东西。