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.
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.
– Vítor Neil Avelino
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?
– Erico Souza
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.
– Vítor Neil Avelino
This is not Code First. This is Database First.
– Leonel Sanches da Silva
@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".
– Leonel Sanches da Silva
@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.
– Erico Souza