A cycle was detected in a LINQ expression exception

前端 未结 4 1738
执笔经年
执笔经年 2020-12-09 20:36

I get the error :

A cycle was detected in a LINQ expression.

in ToList() while trying to do the following:

4条回答
  •  不知归路
    2020-12-09 21:30

    Of course there is a cycle. You are using entityIds in the Where Linq Extension method and it is the query being constructed itself. Instead of modifying the inputted IEnumerable, return a new query as follows:

    private IEnumerable FilterIdsByClient(IEnumerable entityIds)
    {
        var query =
            MyObjectContext.CreateObjectSet()
                .Where(x => x.ClientId == _clientId)
                .Where(x => entityIds.Contains(x.Id))
                .Select(x => x.Id);
    
        return query.ToList();
    }
    

提交回复
热议问题