ADO.NET Entity Framework

43
ADO.NET Entity Framework 井上 大輔 (いのうえ だいすけ) @daisukei777 http://blogs.msdn.com/b/daisukei/ 日本マイクロソフト株式会社 デベロッパー エクスペリエンス & エバンジェリズム統括本部 クラウドプラットフォーム推進部 テクニカル エバンジェリスト

Transcript of ADO.NET Entity Framework

ADO.NET Entity Framework

井上大輔 (いのうえだいすけ)

@daisukei777 http://blogs.msdn.com/b/daisukei/

日本マイクロソフト株式会社

デベロッパーエクスペリエンス&エバンジェリズム統括本部

クラウドプラットフォーム推進部

テクニカルエバンジェリスト

Visual Studio と .NET の新しいアプローチを理解する

ADO.NET Entity Framework の過去と今を理解する。

セッションのゴールSession Takeaways

• Visual Studio Community の機能は、現時点では Visual StudioProfessional と同一

Community 2013

フリーランスなど個人の開発者の方は、商用・非商用問わずアプリケーション開発に利用可能

PC 台数 250 台未満かつ年間売上100万ドル未満の企業の場合、5 ユーザーまで利用可能

以下の目的であれば、だれでも利用可能

トレーニングや授業

学術研究

OSI 認定ライセンスで提供されるオープン ソースの開発

詳細は、ライセンス条項をご確認ください。

Visual Studio Community 利用条件サマリ

Visual Studio Community Web page: http://aka.ms/vscomm2013

次期バージョン Visual Studio 2015 プレビュー版リリース

RTM (正式リリース) は 2015 年を予定※ プレビュー版は Go-live ライセンスではないため運用環境で利用不可

Azure 仮想マシンイメージが利用可能

Visual Studio Ultimate 2015 CTP6 + Windows Server 2012 R2

.NET 2015

.NET Framework 4.6 / .NET Core 5

.NET Compiler Platform (“Roslyn”)

Visual Studio 2015 CTP 6Next Version of Visual Studio

http://aka.ms/jpvs2015preview

.NET Framework & Core

.NET 2015

Next gen JIT (“RyuJIT”)

SIMD (Data Parallelization)

Runtime Compilers.NET Compiler Platform (“Roslyn”)

Languages innovation

.NET Core 5 Libraries

.NET Framework 4.6 Libraries

NuGet packages

ASP.NET 5

ASP.NET 4.6

WPF

Windows Forms

.NET Framework 4.6 .NET Core 5

ASP.NET 5

.NET NativeWindows desktop

Windows mobile devices

Windows embedded devices

ASP.NET 5 for Mac and Linux

.NET Core 5 のクロスプラットフォーム対応

Linux & Mac サポート

(Mono Project)

Visual Studio の Linux サポート(Debug, Docker など)

Sublime Text 拡張

(OmniSharp / Kulture)

.NET オープンソース

Projects• ASP.NET 5

• Entity Framework

• .NET Core 5

• .NET Compiler Platform

• Plus community projects

License• MIT License

Contribute• .NET Foundation

• GitHub

https://github.com/aspnet

https://github.com/microsoft/dotnet

http://www.dotnetfoundation.org

Full .NET CLR

Visual Studio プロジェクトでデフォルトとなる CLR

すべての API セットと後方互換性を持つ

およそ 200 MB, Side-by-Side 実行が可能

Core CLR (クラウドに最適化されたランタイム)

ASP.NET 5 のために完全にモジュール化された CLR

NuGet パッケージとして必要なモジュールだけを組み込める

およそ 11 MB, Side-by-Side 実行可能

Cross-Platform CLR

Linux と Mac OS 対応のクロスプラットフォーム CLR

ASP.NET 5 アプリケーションの Linux や Mac OS 上での開発と実行が可能

3 つの CLRThree Runtimes for ASP.NET 5

.NET の今後Future of .NET

Next gen JIT (“RyuJIT”)

SIMD (Data Parallelization)

ランタイム コンパイラー.NET Compiler Platform (“Roslyn”)

Languages innovation

BCL and PCL

Entity Framework

ライブラリ

ADO.NET Entity Framework

ADO.NET DataSet LINQ to SQL Entity Framework(EF)

N 階層システム

マルチDB 対応

チューニング

データモデルの柔軟性

開発生産性・保守性

将来性 総じて言えば・・・

ADO.NET

DataSet

○ △ ○ △ △ 成熟 機能的にも成熟、情報も豊富。細かいチューニングが必要な業務アプリなどで有効。

LINQ to

SQL

△ × △ △ △ 大きな進化はなし

基本はEFを使えないか検討すべき。マイグレーションツールもあり。

EF○ ○ △ ○ ○ 進化を継

続生産性・保守性が高く、アジャイルな開発現場で有効。Webなどライトなアプリ開発に便利。

相対的に良いことが多い

相対的に細部まで制御出来る

概念モデルを定義

SQL Serverにほぼ特化

相対的に速度は低

EF の進化

• .NET Framework のコアランタイム• 新しいランタイムは NuGet から取得ツール

系は Visual Studio に含まれる

• .NET Framework のランタイム• ツール系は Visual Studio に含まれる

• NuGet から取得• ツール系はDownload Centerから入手• 新しい Visual Studio のリーリースにあわ

せて提供

• NuGet (ぬげっと / にゅーげっと)

– オープンソース ライブラリなどのパッケージ管理の仕組み(インストール、更新、配布)

– Visual Studio で標準採用

– NuGet ギャラリーを利用したパッケージの公開が可能

http://nuget.org/

EF 1

プレゼンテーション層

ドメイン層

データ層

EF

RDB

EF 4

プレゼンテーション層

ドメイン層

データ層

EF

RDB

EF 4.1, 4.2

プレゼンテーション層

ドメイン層

データ層

EFpublic partial class Entry

{public virtual int ID

{

get;

set;

}

RDB

CoC(Convention over Configuration)

CreateDatabaseIfNotExists(Of TContext)

DropCreateDatabaseAlways(Of TContext)

DropCreateDatabaseIfModelChanges(Of TContext)

マルチダイアグラム

enum

ストアドプロシージャと関数のバッチインポートハイライトと

カラーリング

0%

500%

1000%

1500%

2000%

2500%

Handcoded ADO.NET EF Raw SQL EF Compiled Query Entity SQL LINQ to Entities LINQ to SQL

.NET 4.0 100% 199% 262% 1518% 2314% 1650%

.NET 4.5 100% 211% 269% 406% 412% 1350%

Tim

e s

pen

t

Performance in warm execution of query based on key

EF TeamAsynchronous query and save

Connection resiliency

Code-based configuration

Database command interception/logging

Custom Code First conventions

Code First Insert, update, & delete stored procedures

Nested entity types

Improved transaction Support

Multiple contexts per database

DbModelBuilder.HasDefaultSchema

Configurable migrations history table

Creating context with an open connection

Enums, spatial and better performance on .NET 4.0

Default transaction isolation level changed to READ_COMMITTED_SNAPSHOT

contributors23 total contributions

Custom migrations operations

Improved warm up time for large models

Pluggable pluralization & singularization service

DbModelBuilder.Configurations.AddFromAssembly

DbSet.AddRange/RemoveRange

Async , Await キーワードを使った非同期クエリと更新

EFがDBに送るコマンドをアプリコードでインターセプト

ストアドプロシージャのサポート

EF におけるトランザクションのコントロール

DBとのコネクションが失敗した時に自動的に接続

public class MyConfiguration : DbConfiguration{

public MyConfiguration() {

SetExecutionStrategy( "System.Data.SqlClient", () => new SqlAzureExecutionStrategy

(5,TimeSpan.FromSeconds(30)));

} }

Devart dotConnect Data Providers

EF Team contributors

ツールの強化

トランザクションのコミット失敗の処理

LINQ クエリでの ToString、String.Concat、HasFlags のサポート

Index Attribute

Full .NET Framework (ASP.NET & デスクトップ)

RDB

新たなプラットフォーム (Windows Phone, Windows ストア など)

新たなデータストア (非リレーショナル)

Full .NET Framework

Windows Phone

Windows Store

ASP.NET 5

Mac

Linux

リレーショナル & 非リレーショナル

Example providersSQL Server

SQLite

Azure Table Storage

Redis

In Memory (for testing)

まとめ

Microsoft Virtual Academyhttp://aka.ms/msmva

MVAMicrosoft が提供するオンラインラーニングサイト

.NET についてもっと学びたい方は?

ASP.NET 5 概要

http://aka.ms/dev2015_.net

Visual Studioについてもっと学びたい方は?

Visual Studio 2015 Preview

http://aka.ms/dev2015_vs

インフラ技術者、開発者をはじめ、IT に携わるすべてのエンジニアのための技術コンファレンス

開催日時: 5 月 26 日 (火) - 27 日 (水)開催場所: ザ・プリンス パークタワー東京

http://aka.ms/decode15

• Visual Studio 2015 Preview / .NET 2015 Preview

• http://aka.ms/vs2015previewdl

• .NET Core Open Source and Cross-platform

• https://github.com/microsoft/dotnet

• Visual Studio Community 2013

• http://aka.ms/vscomm2013dl

• Visual Studio 2013 Update 4

• http://aka.ms/vs2013ult

Visual Studio 関連リソースResources for Visual Studio

© 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.

The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and

Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.