Code Monkey home page Code Monkey logo

Comments (9)

schotime avatar schotime commented on August 26, 2024

Can you please show me how you are using this? I'm currently using it like this in production.

from npoco.

mystcreater avatar mystcreater commented on August 26, 2024

You just have to create a connection, begin a transaction with this connection, create a npoco database passing the previously created connection in constructor and then trying to call the fetch method of npoco database.

from npoco.

schotime avatar schotime commented on August 26, 2024

Hey, There is a work around, but only if you let NPoco create the transaction. If you need the transaction to be created outside NPoco then I'm proposing the following API. What do you think?

// Should be able to do this
using (var conn = new SqlConnection("connstring"))
{
    conn.Open();

    IDatabase db = new Database(conn);
    db.BeginTransaction();
    var results = db.Execute("insert into abc(name) select 'wow'");
    db.CompleteTransaction();
}
// Otherwise here is what I'm thinking
using (var conn = new SqlConnection("connstring"))
{
    conn.Open();
    var tran = conn.BeginTransaction();

    IDatabase db = new Database(conn);
    db.SetTransaction(tran);
    db.Execute("insert into abc(name) select 'wow'");
    //tran.Commit() or ....
    //db.CompleteTransaction(); can commit here if needed
}

from npoco.

mystcreater avatar mystcreater commented on August 26, 2024

Wow Adam, thank you very much for your support! I think the second solution looks like much more flexible because the database object are in an object that is created after the transaction created but your first solution should also be implemented if it's not the case. Thank you again for your great product.

from npoco.

schotime avatar schotime commented on August 26, 2024

The first solution is what it does now. Will get a new release out this weekend some time. Will be 1.0.3.

from npoco.

schotime avatar schotime commented on August 26, 2024

1.0.3 is out on NuGet. Can you please have a look and let me know.

from npoco.

mystcreater avatar mystcreater commented on August 26, 2024

Thank you, i will look this night ;)

from npoco.

mystcreater avatar mystcreater commented on August 26, 2024

I updated to the newest version and it work perfectly.

This is what I do with my own "session" object.

   public System.Collections.Generic.List<Table> GetTables(Data.Sessions.Session session)
   {
     Database database = new Database(session.Connection.InternalConnection);

     if (session.Connection.Transaction != null)
        database.SetTransaction(session.Connection.Transaction);

     return database.Query<Table>(
        "SELECT Name, SCHEMA_NAME(schema_id) AS SchemaName " +
        "FROM sys.tables " +
        "WHERE name <> 'dtproperties' " +
        "ORDER BY schemaName, name").ToList();
   }

from npoco.

schotime avatar schotime commented on August 26, 2024

Excellent. Thanks for the feedback.

from npoco.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.