First, the difference between LINQ to SQL and the Entity Framework:
Both LINQ to SQL and the Entity Framework are object-relational mapping techniques that contain LINQ functionality. The essential difference between them is that EF does a better job of decoupling the database schema from the type of our query. With EF, the object we're querying is no longer a C # class that exactly corresponds to the database schema, but rather a higher-level abstraction: the Entity Data Model. This gives us extra flexibility, but it also has a loss of performance and simplicity.
LINQ to SQL and the Entity Framework have strengths, and LINQ to SQL is a lightweight ORM framework designed to provide fast application development for SQL Server databases with the benefits of ease of use, simplicity, and high performance. The advantage of the Entity Framework is that it provides better flexibility for creating mappings between database Schemas and entity classes, and it also supports third-party databases in addition to SQL Server through the provider.
In order to use the entity Framework, you need to create a solid data model with the following steps:
1. Right-click on the Models folder in the "Solution Browser" window and select menu item, "Add", "new item", such as:
2. In the dialog box that appears, select data, and then select ADO. NET Entity Data Model (ADO), and named Mydbmodel, for example:
3. Clicking the "Add" button will run the Data Model Wizard.
4. In the Select model content (Choose model Contents), select the "Generate from Database (Generate)" option and click on the "Next" button, such as:
5. In Select data connection (Choose Your), select the Moviesdb.mdf database connection, and if not, you can create a new, such as:
6. Configure the connection properties in the popup dialog box, such as:
7. Click "OK" in the previous step and click on the sub next, such as:
8. Select the Database object and click Finish, such as:
When you are done,
9. After creating the Entity Data Model, you can use the Entity Designer to modify the model. You can open the Entity designer at any time by double-clicking the moviesdbmodel.edmx file in the Models folder in the solution browser.
If you want to rename an entity class, you can double-click on the class name of the Entity designer and enter a new name, such as. Alternatively, you can select an entity in the Entity designer and then modify the name of the entity class in the Properties window.
ASP. NET MVC creates model classes using the Entity Framework