views:

445

answers:

2

What problems will I have if I change my Entity Framework queries from this:

var contracts = from contract in Context.Contracts select contract;

to this:

var contracts = from contract in Context.Contracts select new MyContract{ Key = contract.key, Advertiser = new MyAdvertiser{ Key = contract.Advertiser.Key } };

i.e. Changing from selecting a contract, to selecting a new object based on the columns of the contract.

In either approach, I am mapping the entities to domain objects after load, and back to entities on save.

A: 

I don't think you will have any problem (I'm doing it this way too), just make sure you write a method to do the mappings, so you don't have to repeat them in every query.

Drevak
+3  A: 

There is nothing wrong with this approach. There are a couple of things to keep in mind:

1) Domain objects should always be fully populated, to prevent cases where a domain process attempts to use data that looks like it is there but isn't. If you have same domain processes that don't need the full set of data from a domain object, and you don't want to have to load the 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 which have differing field lists. If performance is critical to this application, make sure you measure the effect that this change has on query performance. It seems like limiting the result set would increase performance, and generally it does, but not always.