Database connection using Asp.net MVC

Asked

Viewed 2,311 times

1

My doubt, maybe it is not somewhat technical, but rather of better concept, usability, or advantages.

I have a good experience in developing Asp.net using webforms, and ultimamento I seek to expand my knowledge by studying Asp.net mvc, and Asp.net web api.

Following a course, I learned to connect in the database, sql server, and also managed to adapt to mysql (which I usually use more), using ADO.NET Entity Data Model. Which creates the class of dbContext, search on my basis all the tables I desire and already creates the classes with the properties.

My question is whether I can also connect to my database without using the ADO.NET Entity Data Model, manually creating the connection string, creating my dbContext, and classes manually?

If so, I would like to learn a little better about the advantages ADO.NET Entity Data Model, whether to use it or not.

  • 1

    Erico, this approach is usually known as code first, it has some tips here: http://msdn.microsoft.com/pt-br/library/hh972463.aspx. I have an example published in http://impactacsharp2.codeplex.com/Sourcecontrol/Latest#Roadmap/Impactacsharp2/Impacta.Repositorios.Ef.Codefirst/Oficinadbcontext.Cs.

  • It was worth @Vítorneilavelino, but so, Code first, I submit the database after I created the classes. And so, maybe my concept is wrong, but for example, when I used webforms, I already had the database created, and in my project I had a class that performs the connection and then the CRUD classes. It is valid, or advantageous to think in the same way in mvc projects?

  • 1

    Erico, I agree that the term code first confuses a little. Basically I interpret it as an alternative to not need to use the designer offered initially by EF. You can have the database created first and then do the mapping manually, ie, create a class in your data access layer that you inherit from Dbcontext and use the templates that were suggested in the links above.

  • 1

    This is not Code First. This is Database First.

  • 1

    @Ericosouza ADO.NET Entity Data Model is a connection provider for Visual Studio with the database. I don’t understand what you want in "connect to my database without using ADO.NET Entity Data Model".

  • @Ciganomorrisonmendez maybe I am an outdated landing and learning some very interesting things in recent times, for example before I did not use the ADO.NET Entity Data Model, using a class of my own that I created in college, about 3 or 4 years ago. It served me perfectly in the webforms projects, and it worked by sending the SQL commands to the database. So in a way I didn’t care. And now I’m getting more intimate with ADO.NET.

Show 1 more comment

1 answer

1


After studying and researching a lot and also learning in practice, I recognize that in an Asp.net mvc project, it is very useful to use the ADO.NET Entity Data Model. I had some difficulty at first to configure the connection with different banks other than the MS Sql Server, like the Mysql and Oracle, but then it was all quiet, and it’s a much more useful and different concept than I was used to using.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.