views:

260

answers:

1

Hi,
I'm developing a WPF application that talks to a database through the Entity Framework, and I'm having huge issues trying to keep the application responsive. The DataContext isn't thread safe, so you can't do data access from background threads. You can't pass objects between DataContexts due to the object tracking (I've tried for 3 weeks...it always sort of works but never in all cases).

All I want to do is keep my application responsive while data access is going on. What patterns have you used with the Entity Framework to achieve this?

Thanks,
Roy

A: 

The EF does not yet implement lazy loading (or at least not well), so that might be part of your performance issue. Layered queries (queries on top of queries) will suffer because of this.

It sounds like you're trying to do some pretty elaborate things with it. Try thinking more in terms of transactions, i.e. Select, Update, Commit; New, Insert, Commit; and Select, Delete, Commit.

Within any given repository or thread, always work with just one DataContext. Passing objects within data contexts is, as you have found out, difficult. But it should be a breeze within the same data context.

Robert Harvey