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 08, 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

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    May 08, 2016 @ 19:21
    Dan Diplo
    0

    You certainly can use Entity Framework with Umbraco, if you wish. I guess the reason people might recommend PetaPoco is that Umbraco already comes with it out-of-the-box and it's a lot more lightweight than EF.

    I found this article very useful on using PetaPoco with Umbraco:

    https://creativewebspecialist.co.uk/2013/07/16/umbraco-petapoco-to-store-blog-comments/

Please Sign in or register to post replies

Write your reply to:

Draft