Albert
Albert

Reputation: 1033

Entity Framework, LINQ and patterns

I've started using EF and LINQ in a project and I'm trying to decide on the best approach/pattern to use. Until now I've been using a custom persistence framework that was based on DataSets and XML configuration. Basically it was a VS Custom Tool that would read the XML configuration file and the DataSets and would generate Object Oriented classes with all the necessary properties/associations/methods. This auto-generated classes then were used from the UI and I had the flexibility to expose only what the UI would need.

Now with EF and LINQ, I'm not comfortable with the idea that the UI can use directly the auto-generated classes and all the LINQ stuff. It seems that this approach would have a very tight integration between UI and the database.

So I'm looking for some pattern that would "hide" all the EF and LINQ goodies and basically limit what the UI can do. Is there any standard way to do this?

Upvotes: 0

Views: 125

Answers (2)

Erik Funkenbusch
Erik Funkenbusch

Reputation: 93474

What you're looking for is an n-tier application. It's not so much a pattern as an architecture. You break your app up into 2 or more pieces, typically 3 composed of UI, business and Data. You might implement this through other patterns such as the Facade or Repository patterns to keep a strong seperation of concerns.

You might also use a Service Layer, which could be implemented by a facade or as a web service.

You would, ideally, pass data through objects called DTO's or Data Transfer Objects, and you might adapt those DTO's by using a view model in your UI (not to be confused with MVVM which another poster erroneously mentioned.)

Beyond that, much of it depends on the type of app you're buiding. Desktop app, server app, web app, etc..

Upvotes: 1

Thebigcheeze
Thebigcheeze

Reputation: 3498

The pattern you're looking for is, in general, Model-View-ViewModel, or MVVM.

Here's a tutorial that seems to hit on the high points of the design pattern: http://csharperimage.jeremylikness.com/2010/04/model-view-viewmodel-mvvm-explained.html

Upvotes: 0

Related Questions