【发布时间】:2017-08-23 17:08:25
【问题描述】:
我正在尝试创建列表索引。但是,由于某种原因,我不断收到以下错误:
无法将 lambda 表达式转换为类型“TEntity”,因为它不是 委托
我已尝试在此问题上进行大量搜索,但我尝试过的所有方法似乎都不起作用。从创建演员表到确保我有正确的Using 语句,我已经尝试了所有方法
这是专门抛出错误的行
int index = items.IndexOf(x => ID(x) == id.Value);
哪个调用了这个方法
protected Int32? ID(TEntity entity)
{
return entity.As<dynamic>().__id;
}
作为参考,其余适用的内容都在这里。
[Element("<div/>"), Editor, IdProperty("__id")]
public abstract class GridEditorBase<TEntity> : EntityGrid<TEntity>, ISetEditValue, IGetEditValue
where TEntity : class, new()
{
private int nextId = 1;
public GridEditorBase(jQueryObject container)
: base(container)
{
}
protected Int32? ID(TEntity entity)
{
return entity.As<dynamic>().__id;
}
protected virtual void Save(ServiceCallOptions opt, Action<ServiceResponse> callback)
{
SaveRequest<TEntity> request = opt.Request.As<SaveRequest<TEntity>>();
TEntity row = Q.DeepClone(request.Entity);
int? id = row.As<dynamic>().__id;
if (id == null)
row.As<dynamic>().__id = nextId++;
if (!ValidateEntity(row, id))
return;
List<TEntity> items = view.GetItems().Clone();
if (id == null)
items.Add(row);
else
{
int index = items.IndexOf(x => ID(x) == id.Value);
items[index] = Q.DeepExtend<TEntity>(new TEntity(), items[index], row);
}
SetEntities(items);
callback(new ServiceResponse());
}
【问题讨论】:
-
查看
IndexOf的签名以了解它实际接受的内容。 -
@Servy 它接受(TEntity 项)
-
那是
TEntity类型的lambda吗?