score:0
I use LINQ to map domain objects to view models. (I use the Entity Framework, but the technique works in any ORM with good LINQ support.) First write a POCO view model, then project onto it:
var pm = from c in Context.Cities
let score = c.Scores.Where(s => s.MonthCode == selectedMonthCode).FirstOrDefault()
select new CityScoresPresentation
{
City = c.Name,
Score = score.Score
};
This is LINQ to Entities. LINQ to SQL works similarly. YMMV with other ORMs LINQ implementations.
I strongly recommend using a view model instead of binding views to ORM-aware types.
score:2
We actually practice a form of Command Query Separation (Greg Young version -- not the Meyer version) so we would at the very least use the NHibernate ICriteria to select the details we want and then use the AliasToBeanTransformer to inject them directly into a DTO.
For our most complex entities we actually have a separated table with all the details a screen needs to display collapsed into a single row (aka OLAP). We can then run queries directly against this table which by-passes the cost of loading a complex entity which contains much more information then our screen needs.
Source: stackoverflow.com
Related Query
- .NET - ORMs and all possible combinations - ViewModel?
- Create all possible combinations of items in a list using Linq and C#
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- Is it possible to automatically prefix all table names in SQL Server and in LINQ to SQL?
- How to get all possible combinations from an array?
- c# dealing with all possible null and non null values
- How do I find all possible combinations of the form ±1 ± 2 ± 3 ± ... ± n = k with LINQ?
- C# LINQ NET 3.5 SP1: Using LINQ to group by two fields and assigning a correlative unique ID (integer number) to all member of the group
- All possible combinations from given sets but without repetition of sets’ internal elements
- How to insert a record in lambda expression and possible way to shorten the length of code
- How to perform .Max() on a property of all objects in a collection and return the object with maximum value
- How to check if all list items have the same value and return it, or return an “otherValue” if they don’t?
- Entity Framework, Code First and Full Text Search
- What does this C# code with an "arrow" mean and how is it called?
- is it possible to Query an Odata service and expand Child of Child entities?
- How to count the number of code lines in a C# solution, without comments and empty lines, and other redundant stuff, etc?
- Excluding one item from list (by Index), and take all others
- Calculate all possible pairs of items from two lists?
- Is it possible to express this code in LINQ?
- I am wondering about the state of connection and impact on code performance by 'yield' while iterating over data reader object
- Recursive LINQ query: select item and all children with subchildren
- Split the string and join all first elements then second element and so on in c#
- Select one parent property and all children using linq
- Select all unique combinations of a single list, with no repeats, using LINQ
- Create all combinations of n*m values
- Generate all Combinations from Multiple (n) Lists
- Is it possible to cancel select and 'Continue' within .Select statement upon a condition?
- Get max & min from Entity Framework, in one query and with best query possible
- How to use LINQ to find all combinations of n items from a set of numbers?
- How to find all possible substrings in a string?
More Query from same tag
- Selecting Multiple Rows from DataTable using Linq
- Lambda expression Linq-to-SQL get from record 5 to 10
- LINQ to SQL - order by, group by and order by each group with skip and take
- Exclude columns where all rows in that column are null or equal to 0 in LINQ
- Where clause that selects all in certain cases
- Filter a list of objects based on a property existing in another list
- Distinct Values in Dictionary<TKey,TValue>
- LINQ GroupBy - Cannot Implicitly convert type
- Json children properties to dictionary
- Convert this double match to LINQ
- Statement is not updating data item
- Linq: Find elements of 2 list with different values but same index
- Omitting optional attributes from generated XML document, following LINQ-to-XML philosophy
- Possible to do this in linq?
- How do I print output in a certain way
- VB.NET sort IEnumerable class
- LINQ GroupBy except null values
- Asp.net MVC3 with LINQ to SQL on multiple identical tables
- How to write a CASE in a group by with Linq-To-Sql?
- How to do "like" on dictionary key?
- SQL performance linq indexes
- using linq with subsonic 3
- Convert Foreach into linq Expression
- How to pass one row of data from controller to view , not as IEnumerable<>
- How to get only the date value from DateTime and count it?
- SQL to IQueryable LINQ
- Consolidate many if conditions to a single LINQ statement if possible
- Is it possible to perform joins across different databases using LINQ?
- Entity Framework 3 - Filter Elements in Chained Navigational Properties
- Convert/Parse many Objects using a member Method with less Code