GDS ADO Extensions is a smalle set of ADO extensiosn to make it easier to work with ADO.
Code Sample:
Map SqlDataReader to Class:
void ReadData()
{
SqlConnection Con = null;
SqlCommand CMD = null;
SqlDataReader DR = null;
try
{
string connectionString = GDS.ADO.Tools.SqlConnectionFunctions.GetConnectionString(properties.Server, properties.Database, properties.User, properties.Password, properties.UseIntegratedSecurity, true);
Con = new SqlConnection(connectionString);
Con.Open();
CMD = new SqlCommand("SELECT * FROM _Model", Con);
Stopwatch sw = new Stopwatch();
sw.Start();
DR = CMD.ExecuteReader();
List<_Model> list = new List<_Model>();
while (DR.Read())
{
list.Add(DR.MapToClass<_Model>());
}
sw.Stop();
if (Debugger.IsAttached)
{
Debugger.Break();
}
else
{
MessageBox.Show($"{list.Count} elements read in {sw.ElapsedMilliseconds} ms.", "Done", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Fail", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
finally
{
if (DR != null && !DR.IsClosed)
DR.Close();
if (Con != null && Con.State != System.Data.ConnectionState.Closed)
Con.Close();
}
}
Update a record (added in version 1.0.1
string connectionString = SqlConnectionFunctions
.GetConnectionString(properties.Server, properties.Database, properties.User, properties.Password, properties.UseIntegratedSecurity, true);
Con = new SqlConnection(connectionString);
Con.Open();
// add a single element
Model m = new Model() { ID = -1, Name = "Super Duper x2" };
var newm = Con.AddUpdate<Model>("Model", m);
// Note, this is not optimized for performance and may even be slow.
// For now, it optimized for smoothness, which means that the class doesn't have to be decorated.
// (attributes are received from server when saving - which is kind of slow, but works better/easier)
Generate Class from Table:
void GetClass()
{
try
{
string connectionString = SqlConnectionFunctions
.GetConnectionString(properties.Server, properties.Database, properties.User, properties.Password, properties.UseIntegratedSecurity, true);
txtClass.Text = SqlDatabaseFunctions
.GenerateClassFromTable("_Model", connectionString, GDS.ADO.Tools.PropertyTypes.DependencyObject, "_Model");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Fail", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
}
How it looks: