I've been using LINQ to SQL for a number of years in an ASP.Net environment. The UI and BLL tiers were separated by a web service, so lazy loading, change tracking, etc were not an option. It was nice in a way because we knew exactly what was going on in the code - we were responsible for persisting changes in the BLL (figuring out if an entity was new/updated), and there were no unexpected surprises due to some lazy-loading going on somewhere.
I've now moved jobs and working on a new desktop system (WPF). There are no boundaries, i.e. the UI tier will directly call the BLL (but see caveat at end). I'm looking to use EF5, but I'm a bit overwhelmed by the number of features, options, etc. that EF provides. I'm hoping I can get answer to a few questions...
Should lazy loading be used across boundaries? Let's say I wanted to display a customer and all their orders, would the UI request just the customer from the BLL, then use lazy loading to access its orders? Doing this in the UI doesn't feel right to me. I'm assuming lazy loading is just something you would use in the BLL.
I believe you can turn off lazy loading using
DbContext.Configuration.LazyLoadingEnabled
, but what if I wanted to use lazy loading in my BLL, but when I return the entity(s) to my UI I don't want the UI from doing any lazy loading?What about change tracking, self-tracking entities and POCOs? What should I use when? It was never an issue for me when I worked with LINQ to SQL (it was across a web service, and ASP.Net so there was no "state", therefore change tracking was irrelevant). I feel like I want to deactivate it all (which is what I'm used to), but I'm afraid that I'll be missing out on some of the EF "goodness". I think I'm worried about not being in control of persisting data.
As I've been playing around and retrieving data using EF, I've noticed in some of the entity hierarchies that some of the property collections (E.g. customer.Orders) contains "proxy" entities. What are these and when would they be useful?
Again I've noticed you can turn proxies off via
DbContext.Configuration.ProxyCreationEnabled
, but the documentation suggests there's more to it than that, and some kind of relationship with the LazyLoadingEnabled setting?EF "code first" seems to be gaining in popularity. What does it give you? I'm used to designing my database in SSMS, not writing lots of classes, annotations, etc!
A final caveat - although the app's UI tier is directly calling methods in the BLL, there's a small chance that in the future we might want to separate them (E.g. via a web service). How would this affect design considerations, and some of the questions that I've raised above?
Apologies for bundling a number of questions together. If I can get answers to them all then hopefully this will be useful for others in my situation in the future.