2017-08-23 6 views
0

リストのインデックスを作成しようとしています。しかし、私は次のエラーを取得しておく何らかの理由:ラムダ式がデリゲートではないため型に変換できません

Cannot convert lambda expression to type 'TEntity' because it is not a delegate

私はこの問題にかなりの検索試してみましたが、私が試したすべてが動作するようには思えません。私はキャストを作成するから、これは特にエラーを投げているラインである私が正しいUsing

を持って保証するすべてのものを試した、このメソッドを呼び出している

int index = items.IndexOf(x => ID(x) == id.Value); 

protected Int32? ID(TEntity entity) 
{ 
    return entity.As<dynamic>().__id; 
} 

参考までに残りの部分はここにあります。あなたは、このように行う可能性があり、IndexOfにアイテムを渡す必要が

[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()); 
    } 
+0

は、署名を見てください。 – Servy

+0

@Servyそれは受け入れる(TEntityアイテム) – Travis

+0

そしてそのタイプの 'TEntity'のラムダですか? – Servy

答えて

0

:IndexOf`は、それが実際に受け入れるものを見るために `ため

int index = items.IndexOf(items.FirstOrDefault(x => ID(x) == id.Value)); 
関連する問題