Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to get data from database table into controller or model without using entity framwork into mvc 3
Posted
Comments
F-ES Sitecore 19-Oct-15 4:37am    
If you don't want to use EF then don't, use ADO.net instead.

You don't want to use EF or don't want to use any ORM?

If you can don't want to use any ORM then you can use ADO.NET directly, but you would be required to write a lot of code, like for parsing DataTable to object list, parsing object properties to SP parameters etc.

For example you will get model into your controller (if you are submitting the form then model binder will bind the data into model) and to commit your changes to database you will have write the parameter SP. After that for each parameter of SP you would required to write manual code to pass the model properties as SP parameter.

Although you can write some generic methods to avoid code redundancy, but still there will be a lot of manual things. So in my personal opinion you should go with EF or any other ORM.
 
Share this answer
 
XML
public IEnumerable<TrusteeEntity> GetTrustees(string urn)
        {
            IList<TrusteeEntity> trustees = new List<TrusteeEntity>();
            using (SqlConnection con = new SqlConnection(DatabaseHelper.MainConnectionString))
            {
                using (SqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = "select tr.Id, tr.FirstName, tr.LastName, tr.Title, tr.Addr1, tr.Addr2, tr.Town, tr.County, tr.Postcode from Trt "+
                                      "inner join Trstees tr on t.Id;
                    con.Open();
                    var reader = cmd.ExecuteReader();
                    ReadT(reader, trustees);
                }
            }
            return trustees;
        }

You can you ADO.NET approach like my example. Or you can use different ORM than Entity framework. Or you can all sql procedure instead... There is a lot of options ;).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900