nvivo / dbhelpers Goto Github PK
View Code? Open in Web Editor NEWDBHelpers
DBHelpers
Hi, awesome work!
does nvivo dbhelps support this like following ?
"select * from (select 1 as Id union all select 2 union all select 3) as X where Id in @Ids",
Today, DbDataReader exposes some methods like GetInt32(int) that allows fast data retrieval, but requires extra steps to check for DBNulls. It also doesn't provide methods to retrieve nullables neither handles field names, only ordinals.
class User {
public string Name { get; set; }
public int? Age { get; set; }
}
var user = db.ExecuteList("select name, age from users", r => new User {
Name = r.IsDBNull(0) ? null : r.GetString(0),
Age = r.IsDBNull(1) ? null : r.GetInt32(1)
});
DBConvert provides easier conversion methods, but the extra method call and method names like "ToNullableDateTimeOffset" makes the code a little bit harder to read.
var user = db.ExecuteList("select name, age from users", r => new User {
Name = DBConvert.ToNullableInt32(r[0]),
Age = DBConvert.ToString(r[1])
});
With extension methods, there could be a syntax like:
Name = reader.Get<string>(0);
Age = reader.Get<int?>(1);
Name = reader.Get<string>("name");
Age = reader.Get<int?>("age");
This would call the corresponding DBConvert method if needed.
Current DataReaderConverter uses System.Convert for type conversions, which doesn't handle nullable types.
It also needs a better converter that can handle other values that comes from databases, including DBNull.
Some methods like ExecuteDataTableAsync/ExecuteDataSetAsync call Task.Run unnecessarily. This should be removed.
Any full source code real application using dbhelpers with good patterns and practices ? code in production ?
A question, Why not Dapper ?
https://github.com/StackExchange/dapper-dot-net
Stackoverflow sites uses Dapper.
Thx
I'm trying to load List by using:
ExecuteList() from my database and it filled my result with 0 instead of 542496808.
My select would return only it: { ID: 542496808 }
I tried using the DBHelper with the following:
_sourceDB = new DBHelper("Source");
here is the connection string defined
<add name="Source" connectionString="data source=workstation;initial catalog=MCQ;integrated security=True;multipleactiveresultsets=True;" providerName="System.Data.SqlClient" />
and it keeps giving error
Connection not initialized
ExecuteDataTable(command) throws ArgumentException: invalid -1 for maxRecords.
i'm not find code about execute store procedure in readme.txt,can u write it?thank u.
All commands accept (DbCommand, DbConnection), but the ones accepting strings do not accept DbConnections. Need to add overloads for that.
I would like to perform queries in transaction/ 1 connection, but ExecuteObject automatically closes connection. In case of provided connection, methoud should not close connection itself:
This works:
using (var connection = db.CreateConnection()) {
connection.Open();
db.ExecuteNonQuery(..., connection);
db.ExecuteNonQuery(..., connection);
db.ExecuteNonQuery(..., connection);
}
But this not:
using (var connection = db.CreateConnection()) {
connection.Open();
db.ExecuteObject(..., connection);
db.ExecuteObject(..., connection); // connection closed exception
db.ExecuteObject(..., connection);
}
Cause: CommandBehavior.CloseConnection in ExecuteReader method
Hello there,
Thanks for the code...
Is there support for transactions?
Regards.
Josep
how to execute Add、Delete and Update methods ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.