What is "code-first"
Entity Framework Code-First is a methodology for mapping between . NET classes and database structures. Classes and properties should be marked with decorating attributes (e.g., [Table("Minhatabela")] or [Column("Minhacoluna")]) or the description for class mapping and its properties can be done by Fluentapi, by calling methods that specify the creation of the data model.
Code-first also operates by convention connected to an instance of a standard Sqlserver database in a database with a name according to the project (for example, creating a project called RestauranteMVC
, the mechanism will try to connect in . /Sqlexpress/Restaurantemvc). If the database is not available (but the SQL Server instance is), the Entity Framework will generate a database according to the classes and properties that have been defined so far. Tables will be named according to the classes defined in the templates, and columns according to the properties of these classes. Properties named ID or [Classname]ID will be created as primary keys. Classes referencing other classes will receive foreign keys, etc.
Code-First can be used not only to create a new database, but also to connect to an existing database structure, and its relationships.