Linq to Sql, Repositories, and Asp.Net MVC ViewData: How to remove redundancy?
Posted
by Dr. Zim
on Stack Overflow
See other posts from Stack Overflow
or by Dr. Zim
Published on 2010-04-06T03:50:57Z
Indexed on
2010/04/06
3:53 UTC
Read the original article
Hit count: 310
Linq to SQL creates objects which are IQueryable and full of relations.
Html Helpers require specific interface objects like IEnumerable<SelectListItem>
.
What I think could happen:
- Reuse the objects from Linq to SQL without all the baggage, i.e., return Pocos from the Linq to SQL objects without additional Domain Model classes?
- Extract objects that easily convert to (or are) Html helper objects like the SelectListItem enumeration?
Is there any way to do this without breaking separation of concerns? Some neat oop trick to bridge the needs?
For example, if this were within a repository, the SelectListItem wouldn't be there. The select new
is a nice way to cut out an object from the Linq to SQL without the baggage but it's still referencing a class that shouldn't be referenced:
IEnumerable<SelectListItem> result = (from record in db.table
select new SelectListItem {
Selected = record.selected,
Text= record.Text,
Value= record.Value }
).AsEnumerable();
© Stack Overflow or respective owner