B
B
Bisekenov2018-03-11 19:53:08
ASP.NET
Bisekenov, 2018-03-11 19:53:08

How to work with ASP.NET MVC database?

Hello! Do not judge strictly, I'm studying MVC. Everything is fine and fine, I work with the database. But there is one question that I can't find an answer to.
When connecting to an existing database, a table is programmatically created from the context. For example there is a table STUD, there are more than 1000 records. I create a context, a repository, I connect, and an empty STUDs table is created in the database and MVC works with it. I tried to create a context with the name STUD like the table, all the codes were gutted, everything does not exactly connect to the finished table. At one of the lessons in youtube it is said that the feature of MVC, I think is nonsense or not?
If it's not difficult, you can have a few examples of how to properly connect to an existing table?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
eRKa, 2018-03-11
@kttotto

You need to connect not to an existing table, but to an existing database. To do this, you need to specify in the web.config file the path to the database and the username / password corresponding to it in the conectionstring. If you specify the connectionString correctly, then there will be a connection to it. Just keep in mind that all your entity models must be implemented in advance for this database and correspond to its schema.
If you need to work with two databases, then create two contexts, each with its own connectionString to the database.
If you mean that in the new database a table was created by hand and filled with data, and the database creates it new and clean, then somewhere there is an error either in the table name or in the way you specified it in DbSet.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question