![](/img/trans.png)
[英]Cannot convert lambda expression to type 'Delegate' because it is not a delegate type MVC 5
[英]Cannot convert lambda expression to type because it is not a delegate
我正在尝试创建列表索引。 但是,由于某种原因,我不断收到以下错误:
无法将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
,您可以这样做:
int index = items.IndexOf(items.FirstOrDefault(x => ID(x) == id.Value));
也许您缺少这些参考文献之一,请尝试添加它们
使用System.Linq;
使用System.Data.Entity;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.