Ways of connection in ASP . NET

Asked

Viewed 84 times

0

I’m a beginner in ASP and C#. I have doubts and this is the real reason to ask here. Before you have to read the politics of questions understand that I am a beginner and I really need help.

I have a question how to connect my ASP application to a database DB First.


As I’m starting out, I decided to gather as much information as possible. I initially read that there are two types of projects: the Code First where classes are first developed and the database is automatically generated on top of that and the Database First: database developed before application.

After that I started researching how to make the connections, then I collected the following information:

  • Ado . net: Native to the .Net. platform All the examples I found were on top of the Code First. All connections are automatically generated
  • Entity Framework: ORM heavily used in applications code first and is not advised to use in applications DB First because the code would be too long and difficult to understand.
  • Dapper: Micro ORM, developed by someone from stack overflow, fast and efficient. Also recommended for applications Code First.
  • Linq: In passing say that it is a mask for SQL strings

Why it is so advised to use all these items in one application DB First?

  • DB First is something that the creators of Orms like EF have left aside and moved on to applications that use Code First as a focus so you should have seen it in many places if you say it is advisable. What is advisable is not always what we need in our applications... Your question is very confusing... I don’t know if you want to make a connection to the bank or know the difference between code first and db first.

  • So I have to reinvent the wheel every time? What happens when I already have a database? Do I have to recreate it? Unviable...

  • No... You can simply create your code first by mapping your existing database ...

  • see documentation https://msdn.microsoft.com/en-us/library/jj200620(v=vs.113). aspx

  • But on some sites I read reported that this mapping makes the code extensive and difficult to understand.

2 answers

0


The question is a little wide, but I believe I can help you because I went through it a few days ago.

It is important to decentralize the application database. How is this done? Through Mapping performed on top of the existing database. I suggest you read this tutorial, will clear up your doubts.

0

Look, in fact, in the examples you gave ADO is the only way to connect to the bank. The others are ORM’s or micro ORM’s, etc.

Both will use ADO to connect to the bank.

Orms convert bank results into (basically) objects. It is worth researching, because there is another meaning and reasons for the existence of Orms.

You should not use all in the same application because imagine the weight and conflicts that would happen if you tried... The Entity itself is already very heavy and very rigid (even sometimes cast). It doesn’t make much sense to mix with others, you understand?

Regarding Db first or Code first. Code first: The database is created according to the classes created in the application. The ORM is used for this.

Db First: The bank already exists and we create the classes from that bank, sometimes, automatically.

Comments: You may already have a database ready in code first, but you should be very careful when creating your classes.

Browser other questions tagged

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