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.
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:
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;
which is read by the old school
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
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/
is working on a reply...