In the last part we installed Entity Framework 6.1.1 with NuGet package management tool in Visual Studio. In this lesson we will learn to create an Entity Model using the Northwind database. Follow the steps below.
- Add a new folder call "Models" in the "Northwind" database
2. Right-click on the "Models" folder and select "Add", the select "New Item"
4. On the "Entity Data Model Wizard" screen select "EF Designer from database" and then select "Next"
The Northwind Entity Model is created
The Entity model context code files are also generated as well. To open the Entity Model designer screen just double click on the NorthwindModel.edmx file
If you look the Web.config file you will see it has been modified significantly with Entity Framework settings without you even opening it. It's all done for you automatically for you.
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration,
visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.
ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<connectionStrings>
<add name="NorthwindEntities" connectionString="
metadata=res://*/Models.NorthwindModel.csdl|res://*/Models.NorthwindModel.ssdl
|res://*/Models.NorthwindModel.msl;
provider=System.Data.SqlClient;provider connection string="
data source=HP-LAPTOP\SQLSERVERDEV;initial
catalog=Northwind;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory,
EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
Blogs in the Entity Framework Series:
- Installing Entity Framework 6.1.1 With NuGet
- Creating Entity Model From an Existing Database Entity Framework 6.1.1
- Using the Entity Framework Objects In ASP.NET Project
- Entity Framework (Database First) Part 4: Using the LINQ and Projection To SELECT Columns From Entities
Great EF6 info! Thanks and keep up the good work.
ReplyDelete