Viele Entwickler nutzen das Entity Framework als Blackbox. In diesem Vortrag wollen wir das Entity Framework entzaubern und einen Blick in die Blackbox werfen. Dabei werden wir darüber sprechen, was bei der Initialisierung des Entity Frameworks geschieht, wie der Status von Entitäten verwaltet wird und auch diskutieren, ob Sie auf dem Kontext tatsächlich Dispose() aufrufen müssen. Wenn Sie also wissen möchten, was das Entity Framework wirklich mit Ihrer Datenbank macht, dann sollten Sie diese Präsentation ansehe.
33. Werte von Engine Edition
• 1 = Personal or Desktop Engine (Not available in SQL Server 2005 and
later versions.)
• 2 = Standard (This is returned for Standard, Web, and Business
Intelligence.)
• 3 = Enterprise (This is returned for Evaluation, Developer, and both
Enterprise editions.)
• 4 = Express (This is returned for Express, Express with Tools and
Express with Advanced Services)
• 5 = SQL Azure
33https://technet.microsoft.com/en-us/library/ms174396(v=sql.110).aspx
34. internal static ServerType GetServerType(DbConnection connection)
{
Debug.Assert(connection.State == ConnectionState.Open, "Expected an open connection");
using (var command = connection.CreateCommand())
{
command.CommandText = "select cast(serverproperty('EngineEdition') as int)";
using (
var reader = DbInterception.Dispatch.Command.Reader(command,
new DbCommandInterceptionContext()))
{
reader.Read();
const int sqlAzureEngineEdition = 5;
return reader.GetInt32(0) == sqlAzureEngineEdition ? ServerType.Cloud :
ServerType.OnPremises;
}
}
}
EntityFramework.SqlServerSqlVersionUtils.cs
35. • select cast(serverproperty('EngineEdition') as int)
• Ermitteln der Datenbankedition (Lokal oder Cloud)
• Notwendig damit angepasste SQL Statements generiert
werden können
EntityFramework.SqlServerSqlServerMigrationSqlGenerator.cs
36. SELECT Count(*)
FROM INFORMATION_SCHEMA.TABLES AS t
WHERE t.TABLE_SCHEMA + '.' + t.TABLE_NAME IN
('dbo.Categories', 'dbo.Products', 'dbo.Order
Details', 'dbo.Orders', 'dbo.Customers',
'dbo.CustomerDemographics', 'dbo.Employees',
'dbo.Territories', 'dbo.Region', 'dbo.Shippers',
'dbo.Suppliers', 'dbo.CustomerCustomerDemo',
'dbo.EmployeeTerritories')
OR t.TABLE_NAME = 'EdmMetadata'
40. SELECT [GroupBy1].[A1] AS [C1]
FROM (SELECT COUNT(1) AS [A1]
FROM [dbo].[__MigrationHistory] AS
[Extent1]
WHERE [Extent1].[ContextKey] =
'EFInternals.Db.NorthwindDb‘
---
SELECT [GroupBy1].[A1] AS [C1]
FROM (SELECT COUNT(1) AS [A1]
FROM [dbo].[__MigrationHistory] AS
[Extent1]) AS [GroupBy1]
54. Change Tracking
using (var db = new NorthwindDb())
{
var shipper = db.Shippers.Find(6);
shipper.Phone =
DateTime.UtcNow.Millisecond.ToString();
db.SaveChanges();
}
64. Meine Dienstleistungen
• Schulungen
• ASP.NET / JavaScript / AngularJS
• Xamarin
• Cordova
• TX Text Control
• Infragistics NetAdvantage
• Team Foundation Server
• .NET Datenzugriff (Entity Framework, NHibernate, Micro O/R Mapper)
• Consulting
• Durchführung von Technologieworkshops
• Code- / Architekturreviews
• Analyse von managed Memory Leaks
• Prototypenentwicklung
• Remote Entwickler-Support
• Projektbegleitendes Coaching
• Softwareentwicklung
• Mobile Apps (Android, iOS, Windows 10, Windows 8, Windows Phone)
• Entwicklung von Web-Anwendungen mit ASP.NET und AngularJS
• Entwicklung von Desktop Anwendungen
64andre@andrekraemer.de| http://andrekraemer.de| http://andrekraemer.de/blog | http://github.com/AndreKraemer