I want to get records from the database using EF and assign the values to a DTO class.Consider the following tables for a Linq query.
TableA,TableB, TableC
F
First thing, I just need to ask whether you can use Entity Framework 4.1 and POCOs (DbContext) and avoid the need for DTO's altoghther?
Assuming that the answer is no, that must be because you are not pulling back all of the fields, or you are somehow altering the "shape" of the data.
In that case, you could change your LINQ query to look something like this:
from t in table
where ...
select new DTOA()
{
TheDtoProperty = theTableProperty,
AndSoOn = AndSoOn
};
The benefit of doing it this way: If you turn on SQL Profiler, you should see that only the columns that you request make it into the actual SQL query. If you query it all first and then pull the values, all of the columns will be pulled down the wire.