How to limit select items with L2E/S?

Posted by orlon on Stack Overflow See other posts from Stack Overflow or by orlon
Published on 2010-06-10T19:58:52Z Indexed on 2010/06/10 20:03 UTC
Read the original article Hit count: 206

This code is a no-go

var errors = (from error in db.ELMAH_Error
         select new
         {
             error.Application,
             error.Host,
             error.Type,
             error.Source,
             error.Message,
             error.User,
             error.StatusCode,
             error.TimeUtc
         }).ToList();

return View(errors);

as it results in a 'requires a model of type IEnumerable' error. The following code of course works fine, but selects all the columns, some of which I'm simply not interested in:

var errors = (from error in db.ELMAH_Error
         select error).ToList();

return View(errors);

I'm brand spanking new to MVC2 + L2E, so maybe I'm just not thinking in the right mindset yet, but this seems counter-intuitive. Is there an easy way to select a limited number of columns, or is this just part of using an ORM?

© Stack Overflow or respective owner

Related posts about linq-to-sql

Related posts about asp.net-mvc-2