Copyright Comminus d.o.o. | Buzinski prilaz 10 | 10000 Zagreb | www.comminus.hr
Entity Framework Core (EF Core)
Marko Šarić
marko.saric@comminus.hr
Copyright Comminus d.o.o.
Content
• What is EF CORE
• EF Core Database Support
• Entity Framework Core vs Entity Framework 6.x
• The Model (Database Context)
• Querying data
• Saving data
• Stored procedures
09.12.2016.
How to use?
.NET Core has reached the 1.1 release. It's cross-platform, open source, and
wicked fast. Plus you can code on your Mac.
Copyright Comminus d.o.o.
09.12.2016.
What is EF Core
• Object-relational mapper (O/RM) that enables .NET developers to work with a
database using .NET objects. It eliminates the need for most of the data-access
code that developers usually need to write.
• Lightweight, extensible, and cross-platform version of Entity Framework.
• Built over a completely new set of core components. EF Core doesn't
automatically inherit all the features from EF6.x.
• Some of these features will show up in future releases (such as lazy loading and connection
resiliency)
• Less commonly used features will not be implemented in EF Core.
Copyright Comminus d.o.o.
09.12.2016.
• Microsoft SQL Server (including SQL Azure)
• Also support for SQL Server Compact Edition
• Memory-Optimized Table support was introduced in EF Core 1.1.0.
• SQLite
• PostgreSQL
• MySQL
• Built-in in-memory database (designed for testing purposes only)
• The Oracle .NET team is evaluating EF Core support, but have not announced
any timing
• Database providers are installed through NuGet
• PM> Install-Package Microsoft.EntityFrameworkCore.SqlServer
• PM> Install-Package Npgsql.EntityFrameworkCore.PostgreSQL
Copyright Comminus d.o.o.
09.12.2016.
Features not in EF Core
• Spatial data types such as SQL Server's geography & geometry
• Graphical visualisation of model
• Loading related data: Lazy
• Stored procedure mapping (stored procedures are supported)
Copyright Comminus d.o.o.
09.12.2016.
The 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.
Querying
Instances of your entity classes are retrieved from the database using Language
Integrated Query (LINQ)
Querying
• Loading Related Data
• Eager loading: related data is loaded from the database as part of the initial
query
• Explicit loading: related data is explicitly loaded from the database at a later
time
Saving data
Data is created, deleted, and modified in the database using instances of your
entity classes
Stored Procedures
• Use FromSql method which executes RAW SQL queries.
Limitations (and misconceptions):
• SQL queries can only be used to return entity types that are part of your model. Therefore, it cannot contain
related data
• The SQL query must return data for all the properties of the entity. So basically your SQL query should be
Select * from {tableName}
• The column names in the result set must match the column names that properties are mapped to
• For INSERT, UPDATE, DELETE queries: ExecuteSqlCommand.
• It returns integer value which indicates the count of affected rows
• ExecuteSqlCommand should be used on context.Database
Copyright Comminus d.o.o.
09.12.2016.
References
Official Technical Documentation
 https://docs.microsoft.com/en-us/ef/
101 LINQ Samples
 https://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b
EF Core 1.0: First Look
 https://app.pluralsight.com/library/courses/play-by-play-ef-core-1-0-first-look-julie-lerman
LINQ Fundamentals with C# 6.0
 https://app.pluralsight.com/library/courses/linq-fundamentals-csharp-6
Building a Web App with ASP.NET Core, MVC 6, EF Core, and Angular
 https://app.pluralsight.com/library/courses/aspdotnetcore-efcore-bootstrap-angular-web-app
/
Copyright Comminus d.o.o.
09.12.2016.
Copyright Comminus d.o.o.
23.11.2016.
Copyright Comminus d.o.o.
23.11.2016.
Hvala na pozornosti

Entity Framework Core (EF Core) Power Point Slide Show

  • 1.
    Copyright Comminus d.o.o.| Buzinski prilaz 10 | 10000 Zagreb | www.comminus.hr Entity Framework Core (EF Core) Marko Šarić marko.saric@comminus.hr
  • 2.
    Copyright Comminus d.o.o. Content •What is EF CORE • EF Core Database Support • Entity Framework Core vs Entity Framework 6.x • The Model (Database Context) • Querying data • Saving data • Stored procedures 09.12.2016.
  • 3.
    How to use? .NETCore has reached the 1.1 release. It's cross-platform, open source, and wicked fast. Plus you can code on your Mac. Copyright Comminus d.o.o. 09.12.2016.
  • 4.
    What is EFCore • Object-relational mapper (O/RM) that enables .NET developers to work with a database using .NET objects. It eliminates the need for most of the data-access code that developers usually need to write. • Lightweight, extensible, and cross-platform version of Entity Framework. • Built over a completely new set of core components. EF Core doesn't automatically inherit all the features from EF6.x. • Some of these features will show up in future releases (such as lazy loading and connection resiliency) • Less commonly used features will not be implemented in EF Core. Copyright Comminus d.o.o. 09.12.2016.
  • 5.
    • Microsoft SQLServer (including SQL Azure) • Also support for SQL Server Compact Edition • Memory-Optimized Table support was introduced in EF Core 1.1.0. • SQLite • PostgreSQL • MySQL • Built-in in-memory database (designed for testing purposes only) • The Oracle .NET team is evaluating EF Core support, but have not announced any timing • Database providers are installed through NuGet • PM> Install-Package Microsoft.EntityFrameworkCore.SqlServer • PM> Install-Package Npgsql.EntityFrameworkCore.PostgreSQL Copyright Comminus d.o.o. 09.12.2016.
  • 6.
    Features not inEF Core • Spatial data types such as SQL Server's geography & geometry • Graphical visualisation of model • Loading related data: Lazy • Stored procedure mapping (stored procedures are supported) Copyright Comminus d.o.o. 09.12.2016.
  • 7.
    The Model A modelis made up of entity classes and a derived context that represents a session with the database, allowing you to query and save data.
  • 8.
    Querying Instances of yourentity classes are retrieved from the database using Language Integrated Query (LINQ)
  • 9.
    Querying • Loading RelatedData • Eager loading: related data is loaded from the database as part of the initial query • Explicit loading: related data is explicitly loaded from the database at a later time
  • 10.
    Saving data Data iscreated, deleted, and modified in the database using instances of your entity classes
  • 12.
    Stored Procedures • UseFromSql method which executes RAW SQL queries. Limitations (and misconceptions): • SQL queries can only be used to return entity types that are part of your model. Therefore, it cannot contain related data • The SQL query must return data for all the properties of the entity. So basically your SQL query should be Select * from {tableName} • The column names in the result set must match the column names that properties are mapped to • For INSERT, UPDATE, DELETE queries: ExecuteSqlCommand. • It returns integer value which indicates the count of affected rows • ExecuteSqlCommand should be used on context.Database Copyright Comminus d.o.o. 09.12.2016.
  • 14.
    References Official Technical Documentation https://docs.microsoft.com/en-us/ef/ 101 LINQ Samples  https://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b EF Core 1.0: First Look  https://app.pluralsight.com/library/courses/play-by-play-ef-core-1-0-first-look-julie-lerman LINQ Fundamentals with C# 6.0  https://app.pluralsight.com/library/courses/linq-fundamentals-csharp-6 Building a Web App with ASP.NET Core, MVC 6, EF Core, and Angular  https://app.pluralsight.com/library/courses/aspdotnetcore-efcore-bootstrap-angular-web-app / Copyright Comminus d.o.o. 09.12.2016.
  • 15.
  • 16.