문제

Can anyone point me towards a current library that provides basic wrapping of ADO.NET functionality? I'm looking for something along the lines of the old SqlHelper class and am not really interested in using the Data Access Application Block (as it's a bit of overkill for my simple needs). What is everyone using for working with ADO.NET directly these days?

Update:

I should note that I'm already working with an ORM (Nhibernate); I've just run up against a situation that requires raw ADO.NET calls - so no need to suggest using an ORM instead of working with ADO.NET

도움이 되었습니까?

해결책 2

I ended up going with Fluent Ado.net for this; great little library for doing the simple out-of-band ado.net stuff that pops up every now and then.

다른 팁

Dan, this is a class that I have built up over a few years. I use ADO.NET extensivly. It supports simple things like Fill, NonQuery, Scalar, but also getting a schema, transactions, bulk inserts, and more.

DataAdapter (VisualStudio 2010 solution)

Let me know if you need any more help using this (note: I removed some links to other objects to post this for you, so if it's broken, just let me know).

I've written my own little helper library (one .cs file) here: https://github.com/jhgbrt/yadal/blob/master/Net.Code.ADONet.SingleFile/Db.cs

You can find the non-joined version, tests, and readme here: https://github.com/jhgbrt/yadal

Hope it helpful:

public static class DbHelper {

        public static IDbCommand CreateCommand(this IDbConnection conn, string sql, params object[] args) {
            if (!(conn is SqlConnection))
                throw new NotSupportedException();
            var command = (SqlCommand)conn.CreateCommand();
            try { 
                var paramterNames = new List<string>(args.Length);
                for (int i = 0; i < args.Length; i++) {
                    string name = "@p" + i;
                    command.Parameters.AddWithValue(name, args[i]);
                    paramterNames.Add(name);
                }
                command.CommandText = string.Format(sql, paramterNames.ToArray());
            }
            catch (Exception) {
                if (command != null)
                    command.Dispose();
                throw;
            }
            return command;
        }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top