Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • AsheM 17 posts 108 karma points
    1 week ago
    AsheM
    0

    Converting a site from U7 to U8 - How do I access a separate database?

    So the site used to access a separate non-umbraco database using var db = new Umbraco.Core.Database("ConnectionString");

    What is the equivalent in Umbraco 8?

  • Lucas Michaelsen 21 posts 177 karma points
    1 week ago
    Lucas Michaelsen
    1

    Hello AsheM

    Umbraco uses PetaPOCO as mini ORM, so you can do a query super easy like that:

    long count = ApplicationContext.Current.DatabaseContext.Database.ExecuteScalar<long>("SELECT Count(*) FROM articles");
    

    So the equivalent thing in U8 is

    var db = new NPoco.Database("connectionString");
    
Please Sign in or register to post replies

Write your reply to:

Draft