I am new to ASP.NET MVC but have done a lot of work with ROR, so I am familiar with the MVC pattern. / P>
I'm curious about the possibilities of handling the database part while using Code First Approach. I was told by an ASP.NET developer associate that you can create an empty database, which is a table with database And do use EF codes first to create tables in that empty database.
Is that correct?
I can not find any tutorials or documentation anywhere on that specific approach. I came from the first methods of code that start with the current database and tables, but the table Without an existing database is not there. I would love to know: If this is possible, if it is not, then what is the next-door approach? thanks thanks at the most basic level You create a class to represent your table, a reference class (derived from DbContext) and then run commands in the Package Manager console to create / update / update migration / scripts database schema directly (EF code) Think of as Tools - & gt; Library Package Manager - & gt; Package Manager Console Once the console window is open, make sure the project with your unit / context is selected in the "Default Project" dropdown at the top of the window and executed The following command: This will create a migration class for you that shows your changes in the database Last Migration if it is the first (that is W are initially empty database), then it will generate a system table called "__MigrationHistory" that find out that migration has already been implemented in the database. Implementing the update-database with the -script flag will generate a SQL script that you can save in Source Control as needed. Can check / check. If you want to update the database without scripts, just leave the -script tag. Ensure that you have a connection string in web.config, whose name is like you, in this example reference category ("database computing"). It can point to your existing database, but it will only track / track changes in those institutions that are defined in your reference category. I have found that sometimes it is necessary to define the context as an add-migration and update-database command: rake DB migrate ).
public class user {public string user name {get; Set;} public string password {Get; Set;}} Public Class DatabaseContacts: DBcinTex {Public DBSet & lt; Users & gt; Users {get; Set;}}
Add-migration "Your Migration Details"
Update- Database-script
add-migration "details of your migration "-connection string name" databasecontext "
No comments:
Post a Comment