tags:

views:

99

answers:

2

Hi, so far I've never dealed with serious DB programming in "native" languages (I'm using the "native" word here as opposition to web-based languages like PHP, thus I assume C# is one of those "native" languages. Probably I should use different word, but I don't know any).

Thus I'm looking for a good example of DB application in C#. This example should show how to:

  • add, remove, edit records
  • list records
  • handle relations

most important for me is to learn the proper way of doing the above things, in example - avoiding loading the whole table to memory (hey, it might have 500 000 records [or more ;) ])

A good example of what I'm looking for is P4A demo - products catalog. This however is written in PHP ;) http://p4a.crealabsfoundation.org/demo/

+1  A: 

There are various examples in C#/.Net on codeplex (take for example MVC Music Store if you want to go with MVC and EF) and many other websites.

The examples you're looking for depend on what application you're building. You can go for Linq2SQL or EntityFramework (Linq2Entities) when working with the databases, if you're not very familiar with SQL (though it helps - a lot), or the classes in System.Data.SqlClient for example.

Either option allows you to do the operations you mentioned above.

Regards...

Padel
I know there are *many* examples, but it's important for me to start with proper one - which shows most proper design pattern.I know SQL, I've built quite a few PHP webapps using pure MySQL, but I started to use frameworks (ORM / AR) to speed up the development.
vic
@vic: There is more than one *proper* design pattern and what counts as proper depends on the situation. I know that that's a somewhat evasive answer, but that's how it is. There's no single *right* answer.
FrustratedWithFormsDesigner
I agree here. Unfortunately I don't think anyone can point you in the exact direction here, but only show you some starting points. If there were only one solution (the right one) why bother with all the existing languages/frameworks etc.
Padel
I believe there are plenty of proper patterns, but there are definitely *destructive* ones. So far I've stumbled upon an example which worked fine for small number of records only. Why? Because it loaded the whole table to the memory. That's why I'm asking for **good** examples. I know there's no single answer, so please - post those good starting points which you know :) Thanks!
vic
+2  A: 

First, good question because I don't know of any really good DeskTop/Db sample applications.

You will have to pick a technology first, C# is just the language. You've only indicated Desktop, that leaves you with a lot of choices:

  • WinForms + DataSets (classic 2003 vintage)
  • WinForms + DataReaders (more lowlevel)
  • WinForms + Entity Framework
  • WPF + DataSets
  • WPF + Entity Framework
  • WPF + MVVM + Entity Framework
  • SilverLight + Entity Framework
  • SilverLight + Data Services

More combinations are possible, and there are other (3rd party) ORMs such as NHibernate.

The WinForms+Datasets/DataReaders is the oldest and simplest tech but not very OOP. You will find a lot of small samples and videos on WindowsClient.NET. Don't overlook the VisualBasic samples.
I will call it very good for small applications, less suitable for larger ones.

The Entity Framework (EF) is newer, lots of (recent) blogging about details. I found one small but rather complete sample on MSDN (but I couldn't find an accompanying article). Do take a look if you consider an ORM.
Very good for larger applications as it supports better layering and (unit-)testing.

Henk Holterman
Thank you :)Indeed, I pointed only a language (which, in fact, does not matter *that* much, as the most important is .NET platform here. I guess I can handle reading VisualBasic/Managed C++) and a platform. The reason is quite obvious - I had no idea I have such a wide variety of choices. I guess I'll stay with WinForms as I don't know WPF nor SilverLight... Also, WinForms suits my needs. I'll have a look at the EF example. Thanks for this summing-up!!
vic
There are other options some gui tech + NHibernate ( the very mature Open source project that "inspired" EF ) comes to mind
Miau
WinForms is perfect for me, but I'll have a look at NHibernate as well. But please, give some more **examples** ! :)
vic