These tips are for Entity Framework Code First (6.0 onwards).
- create the model (info class)
- create your own DbContext class that inherit from DbContext
- create DbSet<> property in your DbContext class. This will return the whole table
- from Package Manager Console (Visual Studio-> View -> Other Windows -> Package Manager Console):
- select the project where the DbContext exist in
- type the command: enable-migrations
- a folder will be created called migration, and inside this folder a class created named Configuration.
- in the Configuration class constructor, AutomaticMigrationsEnabled = true. This will create the DB if it is not exist on SQL server (if you did not change the default connection string, it will be created on localdb that accompanies visual studio). You can view it from Server Explorer or SQL Server Object Explorer in visual studio.
- from Package Manager Console: update-database. This will modify or create the database and run the Configuration.Seed method.
- in web.config (the configuration file related to the application), entityFramework/defaultConnectionFactory/
- change the type property to be “System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework”
- in entityFramework/defaultConnectionFactory/parameters/parameter/
- change the value property to contain the connection string, for example (Data Source=.; Initial Catalog=MyDB Integrated Security=True; MultipleActiveResultSets=True)