Copied to clipboard

Flag this post as spam?

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


  • AsheM 19 posts 120 karma points
    Nov 17, 2021 @ 19:08
    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 32 posts 233 karma points
    Nov 17, 2021 @ 23:18
    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