What problems am I having with Entity Framework, select specific columns instead of the whole entity?
What problems do I have if I change Entity Framework queries:
var contracts = from contract in Context.Contracts select contract;
:
var contracts = from contract in Context.Contracts select new MyContract{ Key = contract.key, Advertiser = new MyAdvertiser{ Key = contract.Advertiser.Key } };
i.e. Move from contract selection to new object selection based on contract columns.
In either approach, I map objects to domain objects after loading and back to entities on saving.
a source to share
There is nothing wrong with this approach. There are a few things to keep in mind:
1) Domain objects should always be fully populated to prevent cases where the domain process tries to use data that looks like it is but is not. If you have the same domain processes that do not need the full set of data from the domain object, and you donโt want to load unnecessary data, create a second domain object for use in those processes.
2) Database servers can optimize queries that have identical field lists better than queries with different field lists. If performance is important to this application, make sure you measure the effect this change has on query performance. It seems that limiting the result set will lead to better performance, and this usually happens, but not always.
a source to share