Copied to clipboard

Flag this post as spam?

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


  • DAVID 5 posts 75 karma points
    May 06, 2016 @ 14:49
    DAVID
    0

    SQL query in controller to Data Access Layer

    Hi guys,

    My company have recently purchased an Umbraco website. It uses an SQL query with a datareader to read information from an external database to display in a view. Obviously with it being an sql query with a datareader the code is very out of date and it is also stored in the controller which we are not happy about.

    In the controller we have code like;

    string commandString = @" sql query";
    

    which is read by the old school

    string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["string"].ConnectionString;
    
            SqlConnection sqlCon = new SqlConnection(connectionString);
            sqlCon.Open();
    
            SqlCommand sqlCmd = new SqlCommand(commandString, sqlCon);
            SqlDataReader dataReader = sqlCmd.ExecuteReader();
    
            if (dataReader.HasRows)
            {
                while (dataReader.Read())
                { etc etc
    

    I have some development experience but probably not enough to fix this issue.

    I need to change this so we have a data access layer, which the controller will access to invoke the method to display the information.

    I have read a lot of conflicting things that Umbraco should not use Entity Framework but should use PetaPoco instead.

    I'm looking for any help, or guides which i could follow.

    cheers for any help

  • DAVID 5 posts 75 karma points
    May 08, 2016 @ 10:00
    DAVID
    0

    bump

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    May 08, 2016 @ 20:53
    David Brendel
    0

    Hi David,

    I tested EntityFramework to work with Umbraco and I don't think that there should be a problem.

    PetaPoco is used by Umbraco itself and should be used if you want to access the database Umbraco is installed in.

    It is easy to use and lightweight.

    What you use as the data access layer is up to you. Think you can use what ever you want to access the external DB.

    Regards David

Please Sign in or register to post replies

Write your reply to:

Draft