我无法为linq sql选择器的连接部分创建可重用的选择器。 它现在如何运作:
var result = (from player in context.Players
select new
{
FullName = (string.IsNullOrEmpty(player.FirstName) ? string.Empty : player.FirstName + " ") + player.LastName
FirstName = player.FirstName,
LastName = player.LastName,
Street = player.Street,
}).FirstOrDefault();
我的需要:(我想在多个其他linq sql查询中重用DynamicFullNameSelector()
)
var result = (from player in context.Players
select new
{
FullName = DynamicFullNameSelector(),
FirstName = player.FirstName,
}).FirstOrDefault();
我尝试了LINQ Dynamic Expressions芽的部分我不知道如何存档。
我也尝试过:(使用Combine功能)
Expression<Func<Player, string>> firstName = p => p.FirstName;
Expression<Func<Player, string>> lastName = p => p.LastName;
Expression<Func<Player, string>> fullnameJoin = DynamicQueryable.Combine(firstName, lastName, (a, b) => a + ", , " + b);
var result = (from player in context.Players
select new
{
FullName = fullnameJoin,
FirstName = player.FirstName,
}).FirstOrDefault();
Bud然后我得到如下例外:'LINQ to Entities中不支持LINQ表达式节点类型'Lambda'。'
有什么想法吗?