views:

48

answers:

5

I have a simple C# Application that requires access to an admin table which persists two variables.

Can someone tell me what is the fastest(in terms of dev time) method to interact with the database to retrieve and update the table. I don't wish to create an entire data layer just to gain access to a single table?

A: 

Linq To SQL is the best choice. You drag-and-drop your table from DB, get class generated then you can access your table as if it is just a variable in your program. I liked this tutorial: http://www.thereforesystems.com/linq-to-sql-tutorial/ but there are many others, just google.

Andrey
This is a good choice if you are using SQL Server. LINQ to SQL is not compatible with any other databases.
Matt Greer
A: 

You should use one of the existing ORM(-like) frameworks out there, such as:

  • LINQ-to-Entities (preferred, you have support for it out of the box in VS.NET)
  • LINQ-to-SQL (not so preferred, support from MS is waning and only supports SQL Server)
  • NHibernate (you will need third party tools for design support in VS.NET)

Most (if not all) of these will allow you to specify your data source and simply drag tables to design surfaces at which point your Data Transfer Objects will be created for you, as well as the mechanisms to query and persist them back to the data store.

casperOne
"fastest(in terms of dev time)" is definitely L2S
Andrey
A: 

I'd go with Ado.Net and stored procedures

fearofawhackplanet
noo please. this is outdated. Linq to sql is much better.
Andrey
@Andrey, who told you that ADO.NET is outdated? Have you read this (http://ayende.com/Blog/archive/2008/10/31/microsoft-kills-linq-to-sql.aspx)? I guess you haven't. Or maybe you are referring to Linq to Entities which is different.
Darin Dimitrov
@Darin Dimitrov i read that post. ADO.Net is not outdated, but there is no reason to use it directly these days when you have much more powerful instruments.
Andrey
@Andrey: L2S is **built on** ADO.NET. In what possible way would an ORM solution be of use in a database that **has no relations**? The guy only has one table!
fearofawhackplanet
@Andrey, of course there are reason to use it directly. The scenario described here is a perfectly valid reason to use it.
Darin Dimitrov
@fearofawhackplanet i know. but today he has one table, tomorrow two, day after tomorrow 4. using L2S is not harder than using ADO.net. So why use it?
Andrey
and p.s. Andrey, some would argue L2S is now outdated since MS decided to push EF as their primary ORM tool.
fearofawhackplanet
@Andrey: if the day after tomorrow he has 4 tables, he might consider binning his Ado.Net code that took him all of 2 minutes to write and replacing it with a dedicated data layer. For his current requirements though, L2S would be ridiculous choice.
fearofawhackplanet
+2  A: 

Plain old ADO.NET should be fine:

using (var conn = new SqlConnection("SOME CONNECTION STRING"))
using (var cmd = conn.CreateCommand())
{
    conn.Open();
    cmd.CommandText = "UPDATE mytable SET foo = 'bar'";
    cmd.ExecuteNonQuery();
}
Darin Dimitrov
and when you need to select data from table to your collection you have to map your data. and here the pain will start. MS suggest Linq to SQL and Linq to Entities to solve this out of the box. why not to use it?
Andrey
I totally agree with ADO.NET. Solve the problem at hand as directly and as simply as possible. If the app grows and those two columns in one table becomes a full fledged schema, then move onto an ORM. In the mean time, this is simple as pie.
Matt Greer
A: 

What version of .NET do you use? If 3.5 or later, use LINQ2SQL marked up with attributes from the http://msdn.microsoft.com/en-us/library/system.data.linq.mapping.aspx namespace.

STO