Example: confidence

Entity Framework Documentation - Read the Docs

Entity Framework DocumentationRelease 14, 2016 Contents1 Entity Framework Entity Framework Core .. Model .. Data ..42 getting started on Full .NET (Console, WinForms, WPF, etc.) .. started on .NET Core (Windows, OSX, Linux, etc.) .. started on Core .. started on Universal Windows Platform (UWP) ..333 Creating a & Excluding Types .. & Excluding Properties .. (primary) .. Properties .. properties .. Length .. Tokens .. Properties .. Indexes .. Alternate Keys .. Inheritance .. Backing Fields .. Relational Database Modeling .. Methods of configuration ..884 Querying Query .. Related Data .. vs. Server Evaluation .. vs. No-Tracking .. SQL Queries .. Query Works ..995 Saving Save .. Data .. Delete .. Conflicts .. Entities .. explicit values for generated properties .. 1126 EF Core vs. One Is Right for You.

1 Entity Framework Core 3 ... we’d recommend one of our Getting Started guides to get you started with EF Core. 1.1Get Entity Framework Core ... With EF Core, data access is performed using a model. A model is made up of entity classes and a derived context that represents a session with the database, allowing you to query and save data. ...

Tags:

  Entity, Framework, Getting, Started, Getting started, Entity framework

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Entity Framework Documentation - Read the Docs

1 Entity Framework DocumentationRelease 14, 2016 Contents1 Entity Framework Entity Framework Core .. Model .. Data ..42 getting started on Full .NET (Console, WinForms, WPF, etc.) .. started on .NET Core (Windows, OSX, Linux, etc.) .. started on Core .. started on Universal Windows Platform (UWP) ..333 Creating a & Excluding Types .. & Excluding Properties .. (primary) .. Properties .. properties .. Length .. Tokens .. Properties .. Indexes .. Alternate Keys .. Inheritance .. Backing Fields .. Relational Database Modeling .. Methods of configuration ..884 Querying Query .. Related Data .. vs. Server Evaluation .. vs. No-Tracking .. SQL Queries .. Query Works ..995 Saving Save .. Data .. Delete .. Conflicts .. Entities .. explicit values for generated properties .. 1126 EF Core vs. One Is Right for You.

2 Comparison .. from to EF Core .. and EF Core in the Same Application .. 1247 Database SQL Server .. (PostgreSQL) .. (Official) .. (MySQL) .. SQL Server Compact Edition .. Data Servers .. (for Testing) .. (MySQL, Oracle, PostgreSQL, SQLite, DB2, SQL Server, and more) .. Oracle (Coming Soon) .. 1358 Strings .. with InMemory .. a DbContext .. from RC1 to RC2 .. from RC2 to RTM .. Line Reference .. 1689 Get Entity Framework Core17510 The Model17711 Querying17912 Saving Data181iiEntity Framework Documentation , Release :This Documentation is for EF Core. For and earlier release see :This Documentation is for EF Core. For and earlier release see Framework Documentation , Release Framework CoreEntity Framework (EF) Core is a lightweight and extensible version of the popular Entity Framework data Core is an object-relational mapper (O/RM) that enables.

3 NET developers to work with a database using .NETobjects. It eliminates the need for most of the data-access code that developers usually need to write. EF Coresupports many database engines, seeDatabase Providersfor you like to learn by writing code, we d recommend one of ourGetting Startedguides to get you started with Get Entity Framework CoreInstall the NuGet package for the database provider you want to use. SeeDatabase Providersfor > Install-Package The ModelWith EF Core, data access is performed using a model. A model is made up of Entity classes and a derived contextthat represents a session with the database, allowing you to query and save data. SeeCreating a Modelto learn can generate a model from an existing database, hand code a model to match your database, or use EF Migrationsto create a database from your model (and evolve it as your model changes over time).1using ;2using ;34namespace Intro5{6public class BloggingContext: DbContext7{8publicDbSet<Blog> Blogs {get;set; }9publicDbSet<Post> Posts {get;set; }1011protected override voidOnConfiguring(DbContextOptionsBuilde r optionsBuilder)12{ (@"Server=(localdb)\mssqllocaldb;Databas e=MyDatabase;Trusted_Connection=True;"); 14}15}3 Entity Framework Documentation , Release class Blog18{19public intBlogId {get;set; }20public stringUrl {get;set; }2122publicList<Post> Posts {get;set; }23}2425public class Post26{27public intPostId {get;set; }28public stringTitle {get;set; }29public stringContent {get;set; }3031public intBlogId {get;set; }32publicBlog Blog {get;set; }33}34} QueryingInstances of your Entity classes are retrieved from the database using Language Integrated Query (LINQ).

4 SeeQuery-ing Datato learn (vardb =newBloggingContext())2{3varblogs = (b => > 3) (b => ) ();7} Saving DataData is created, deleted, and modified in the database using instances of your Entity classes. SeeSaving Datato (vardb =newBloggingContext())2{3varblog =newBlog { Url = " " }; (blog); ();6}Caution:This Documentation is for EF Core. For and earlier release see 1. Entity Framework CoreCHAPTER2 getting StartedThe following articles provide Documentation for using EF on different :This Documentation is for EF Core. For and earlier release see getting started on Full .NET (Console, WinForms, WPF, etc.)These 101 tutorials require no previous knowledge of Entity Framework (EF) or Visual Studio. They will take youstep-by-step through creating a simple application that queries and saves data from a Framework can create a model based on an existing database, or create a database for you based on your following tutorials will demonstrate both of these approaches using a Console Application.

5 You can use thetechniques learned in these tutorials in any application that targets Full .NET, including WPF and Available TutorialsCaution:This Documentation is for EF Core. For and earlier release see Application to New DatabaseIn this walkthrough, you will build a console application that performs basic data access against a Microsoft SQLS erver database using Entity Framework . You will use migrations to create the database from your this article: Prerequisites Create a new project Install Entity Framework Create your model Create your database Use your modelTip:You can view this article s sample on Framework Documentation , Release following prerequisites are needed to complete this walkthrough: Visual Studio 2015 Update 3 Latest version of NuGet Package Manager Latest version of Windows PowerShellCreate a new project Open Visual Studio 2015 File New From the left menu selectTemplates Visual C# Windows Select theConsole Applicationproject template Ensure you are Framework later Give the project a name and clickOKInstall Entity FrameworkTo use EF Core, install the package for the database provider(s) you want to target.

6 This walkthrough uses SQL a list of available providers seeDatabase Providers. Tools NuGet Package Manager Package Manager Console RunInstall-Package in this walkthrough we will also be using some Entity Framework commands to maintain the database. So wewill install the commands package as well. RunInstall-Package -PreCreate your modelNow it s time to define a context and Entity classes that make up your model. Project Add the name and clickOK Replace the contents of the file with the following code1using ;2using ;34namespace {6public class BloggingContext: DbContext7{8publicDbSet<Blog> Blogs {get;set; }9publicDbSet<Post> Posts {get;set; }1011protected override voidOnConfiguring(DbContextOptionsBuilde r optionsBuilder)6 Chapter 2. getting StartedEntity Framework Documentation , Release class Blog18{19public intBlogId {get;set; }20public stringUrl {get;set; }2122publicList<Post> Posts {get;set; }23}2425public class Post26{27public intPostId {get;set; }28public stringTitle {get;set; }29public stringContent {get;set; }3031public intBlogId {get;set; }32publicBlog Blog {get;set; }33}34}Tip:In a real application you would put each class in a separate file and put the connection string in and read it out usingConfigurationManager.}

7 For the sake of simplicity, we are putting everything in a singlecode file for this your databaseNow that you have a model, you can use migrations to create a database for you. Tools > NuGet Package Manager > Package Manager Console RunAdd-Migration MyFirstMigrationto scaffold a migration to create the initial set of tables foryour model. RunUpdate-Databaseto apply the new migration to the database. Because your database doesn t exist yet,it will be created for you before the migration is :If you make future changes to your model, you can use theAdd-Migrationcommand to scaffold a newmigration to make the corresponding schema changes to the database. Once you have checked the scaffolded code (andmade any required changes), you can use theUpdate-Databasecommand to apply the changes to the uses a__EFMigrationsHistorytable in the database to keep track of which migrations have already beenapplied to the your modelYou can now use your model to perform data access.

8 getting started on Full .NET (Console, WinForms, WPF, etc.)7 Entity Framework Documentation , Release Replace the contents of the file with the following code1using System;23namespace {5class Program6{7static voidMain(string[] args)8{9using(vardb =newBloggingContext())10{ (newBlog { Url = " " });12varcount = (); ("{0} records saved to database", count); (); ("All blogs in database:");17foreach( )18{ (" - {0}", );20}21}22}23}24} Debug Start Without DebuggingYou will see that one blog is saved to the database and then the details of all blogs are printed to the :This Documentation is for EF Core. For and earlier release see Application to Existing Database (Database First)In this walkthrough, you will build a console application that performs basic data access against a Microsoft SQLS erver database using Entity Framework . You will use reverse engineering to create an Entity Framework modelbased on an existing 2. getting StartedEntity Framework Documentation , Release this article: Prerequisites Blogging database Create a new project Install Entity Framework Reverse engineer your model Use your modelTip:You can view this article s sample on following prerequisites are needed to complete this walkthrough: Visual Studio 2015 Update 3 Latest version of NuGet Package Manager Latest version of Windows PowerShell Blogging databaseBlogging databaseThis tutorial uses aBloggingdatabase on your LocalDb instance as the existing :If you have already created theBloggingdatabase as part of another tutorial, you can skip these steps.

9 Open Visual Studio Tools Connect to SelectMicrosoft SQL Serverand clickContinue Enter(localdb)\mssqllocaldbas theServer Name Entermasteras theDatabase Nameand clickOK The master database is now displayed underData ConnectionsinServer Explorer Right-click on the database inServer Explorerand selectNew Query Copy the script, listed below, into the query editor Right-click on the query editor and selectExecute1 CREATE DATABASE[Blogging]2GO34 USE [Blogging]5GO67 CREATE TABLE[Blog] (8[BlogId] intNOT NULL IDENTITY,9[Url] nvarchar(max)NOT NULL,10 CONSTRAINT[PK_Blog]PRIMARY KEY([BlogId])11); getting started on Full .NET (Console, WinForms, WPF, etc.)9 Entity Framework Documentation , Release TABLE[Post] (15[PostId] intNOT NULL IDENTITY,16[BlogId] intNOT NULL,17[Content] nvarchar(max),18[Title] nvarchar(max),19 CONSTRAINT[PK_Post]PRIMARY KEY([PostId]),20 CONSTRAINT[FK_Post_Blog_BlogId]FOREIGN KEY([BlogId])REFERENCES[Blog] ([BlogId])ON DELETE CASCADE21);22GO2324 INSERT INTO[Blog] (Url)VALUES25(' '),26(' '),27(' ')28 GOCreate a new project Open Visual Studio 2015 File New From the left menu selectTemplates Visual C# Windows Select theConsole Applicationproject template Ensure you are Framework later Give the project a name and clickOKInstall Entity FrameworkTo use EF Core, install the package for the database provider(s) you want to target.

10 This walkthrough uses SQL a list of available providers seeDatabase Providers. Tools NuGet Package Manager Package Manager Console RunInstall-Package enable reverse engineering from an existing database we need to install a couple of other packages too. RunInstall-Package -Pre RunInstall-Package engineer your modelNow it s time to create the EF model based on your existing database. Tools > NuGet Package Manager > Package Manager Console Run the following command to create a model from the existing databaseScaffold-DbContext "Server=(localdb)\mssqllocaldb;Database= Blogging;Trusted_Connection=True;" 2. getting StartedEntity Framework Documentation , Release reverse engineer process created Entity classes and a derived context based on the schema of the existing Entity classes are simple C# objects that represent the data you will be querying and System;2using ;34namespace {6public partial class Blog7{8publicBlog()9{10 Post =newHashSet<Post>();11}1213public intBlogId {get;set; }14public stringUrl {get;set; }1516public virtualICollection<Post> Post {get;set; }17}18}The context represents a session with the database and allows you to query and save instances of the Entity ;2using ;34namespace {6public partial class BloggingContext: DbContext7{8protected override voidOnConfiguring(DbContextOptionsBuilde r optionsBuilder)9{10#warning To protect potentially sensitive information in your connection string, you should move it out of source code.}}}


Related search queries