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();