Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
The vast majority of the guides I've read just use mock-ups in place of a real database (supposedly for simplicity) and then don't explain how to actually use a real database.

The rest of them are...complicated.

Most of the guides I've seen that use real databases are geared toward designing Enterprise applications and tend to involve terms like persistence ignorance, dependency injection, line of business, service layer, WCF, Entity Framework, POCOs, and inversion of control (not one of which I'd heard of a few weeks ago).

Ultimately all I'm trying to do is learn enough to make a personal DVD tracking program for myself. It should be a standalone desktop application. Not some huge enterprise thing.

The book I've been relying on (mainly because it breaks things down in a way I can kinda understand), MVVM Survival Guide for Enterprise Architectures in Silverlight and WPF specifically says:
You should only introduce a service layer in your project if it's
needed. Each new architectural feature we will cover in this text
will provide benefits for a cost. It's extremely important that you are
familiar with the trade-offs and only add what you need. If you are
writing an internal tool, adding a Service Layer might be overkill and
provide no ROI to your project.


Unfortunately, the way the book's structured, it introduces the service layer (and persistence ignorance and WCF) long before it gets around to the "no code in the code behind" part and I can't tell how to separate the two.

So here's the question: for a personal use program: how should I go about working with a database? Is WCF necessary? If so, how do you set it up to create a standalone application? If not, what should I do instead?

(If you need more details of the program I'm trying to create, please say so and I'll include them.)
Posted
Comments
Kenneth Haugland 18-Apr-15 3:25am    
Perhaps a valid suggestion would be this:
http://www.codeproject.com/Articles/474212/Zombie-Explorer-An-n-tier-application-from-top-to

1 solution

I assume you didn't pick up programming for doing this one project and intend to drop it as soon as you're done with it, right? ;) What I mean: Don't shy away from at least trying to design and build it in a no-nonsense way because you'll learn by doing so. That's not to say you should design it like an enterprise application.

WCF is a transport/remoting layer. When correctly implemented and not abused, WCF doesn't add anything of value to an application beyond enabling to split it across tiers. If your application should run on a single PC, you won't need it.

My suggestion: Build a repository layer for your database access and use that repository from your ViewModels. The repository exposes the functionality to query and modify your data and hides the database-specific stuff. If you would want to change either your database or make your application remote-able later, you would have one central point where you would have to make changes and your ViewModels wouldn't have to be touched at all (ideally).

While the article suggested by Kenneth is really excellent, I assume it will be one step too advanced and too intermingled with technology you're not familiar with yet. I suggest search for general explanations of the repository pattern on the webs and for articles that demonstrate it using ADO.NET for database access (in contrast to Entity Framework).
 
Share this answer
 
Comments
rayden54 20-Apr-15 0:36am    
Why ADO.NET instead of Entity Framework?
Sascha Lefèvre 20-Apr-15 3:54am    
That was just assuming you would want to limit the amount of new technology used in a project (which I would find reasonable). ADO.NET is perfectly okay; Entity Framework is mostly a convenience thing in big(ger) projects and comes with a much steeper learning curve. But if you want to give it a try, go for it.
rayden54 20-Apr-15 20:38pm    
Do you still use a repository layer with Entity Framework or not? I seem to be finding contradictory info in that regard (it might just be that some of it's outdated)?

I asked about EF partly because that's what I was researching before I asked the question, but also because everything I'm finding for ADO.NET and repository pattern seems to be for MVC.
Sascha Lefèvre 20-Apr-15 21:15pm    
Yes, it's contradictory. If I'd use EF, I probably wouldn't use a repository. Judging from what I've gathered it's an old habit back from where it made (more) sense (early versions of EF). But I've actually never used EF (but another ORM instead). I'm currently writing my own ORM which will have a generic repository so that applications I'll build on top of it won't need a dedicated repository.

The repository pattern, ADO.NET and EF have absolutely nothing to do with MVC. It's just that it's so common that people use these technologies together that many think of them as if there was some dependency. You can use any of those without using any of the other, even the repository pattern doesn't neccessarily require a database (could be anything instead where data is going in and out).

Bottom line: If you go with ADO.NET, a repository absolutely makes sense. For EF, maybe, probably not so much.
rayden54 20-Apr-15 21:58pm    
So if I do use EF, what would I use instead of the repository pattern?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900