Closed blackholeearth closed 1 year ago
example crud class: too see unnecessary boilerplate
public class ARACHAR_crud
{
public List<ARACHAR> get()
{
using (IDatabase db = new Database("constr") )
{
var li = db.Fetch<ARACHAR>();
return li;
}
}
public void delete(int pkey)
{
using (IDatabase db = plakadb.new_db_con())
{
db.Delete<ARACHAR>(pkey);
}
}
public void insert(ARACHAR poco)
{
using (IDatabase db = plakadb.new_db_con())
{
db.Insert<ARACHAR>(poco);
}
}
public void update(ARACHAR poco , int pkey)
{
using (IDatabase db = plakadb.new_db_con())
{
db.Update(poco, pkey);
}
}
}
Database does auto close if you don't explicitly call OpenSharedConnection()
edit: yes. i don't explicitly call OpenSharedConnection() .
so the expected thing is already working as i expected ??
this is already automated , i dont have to use using statement, ??
var li = db.Fetch<MyPoco>();
Well, you never call OpenSharedConnection() so I guess so.
thats good . thank you. im relived to hear that.
but this is. FAQ - able. lots of newbies to npoco are probably wondering about this.
thank you. for this good library.
question: is there a way to get rid of using statements , make npoco automatically open close. ?
user story: library is great, but for simple crud operations, this is just too much boiler plate. i have to write crud class just to hide this. (example class is at bottom/at 2nd comment)
current:
expected either this:
expected or this: