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.
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
bump
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
is working on a reply...