I am calling the LINQ extension method AsQueryable off of a generic list. It throws StackOverflowException exception when I access it. This is a similar technique used in the NerdDinner asp.net mvc demo app. What am I doing wrong?
class FakeUserRepository : IUserRepository
{
List<User> users = new List<User>();
public FakeUserRepository() {
users.Add(new User() {
UserID = new Guid("2C3028AC-B51C-4AA6-8E19-AF962AC07EE7"),
DisplayName = "User1"
});
users.Add(new User() {
UserID = new Guid("EBA48956-2BFE-4C03-8D1B-29747FA7DB25"),
DisplayName = "User2"
});
}
public IQueryable<User> Users {
get { return users.AsQueryable(); }
}
}
public interface IUserRepository
{
IQueryable<User> Users { get; }
}
public class MyController : Controller
{
IUserRepository _userRepository;
public MyController(IUserRepository userRepository) {
_userRepository = userRepository;
}
protected override void Execute(System.Web.Routing.RequestContext requestContext) {
Guid userID = new Guid("2C3028AC-B51C-4AA6-8E19-AF962AC07EE7");
if (requestContext.HttpContext.Request.IsAuthenticated) {
var query = (from u in _userRepository.Users
where u.UserID == userID
select new {
u.DisplayName
}).FirstOrDefault();
ViewData["displayName"] = query.DisplayName;
}
base.Execute(requestContext);
}
}