Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

MVPCONF Latam 2019

130 views

Published on

Deep-Dive on EntityFrameworkCore

Published in: Software
  • Be the first to comment

  • Be the first to like this

MVPCONF Latam 2019

  1. 1. 12 e 13 de abril de 2019 São Paulo, Brasil Conectando Pessoas, Processos e Tecnologia
  2. 2. #MVPConf Trilha .NET Deep-Dive on EntityFramework Core 2.2/3.0 Rafael Almeida Microsoft MVP
  3. 3. #MVPConf YouTube.com/codereadybr LinkedIn.com/in/ralmsdeveloper Twitter.com /ralmsdeveloper Github.com/ralmsdeveloper Rafael Almeida Microsoft MVP, MCC & MCP Arquiteto de Sistemas at STONE Casado e pai de três princesas, as mais lindas! Victória, Maria Heloysa e Maria Eduarda Criador/Mantenedor EFCore.FirebirdSQL Contribuidor projetos Github (Microsoft Open Source) EntityFramework Core e EntityFramework Core for Oracle (Microsoft) .ralms.net
  4. 4. Doação para Entidades #MVPConf Toda a renda obtida com a venda dos ingressos para o MVPConf LATAM 2019 serão doados para cinco Entidades beneficentes. Uma em cada região do Brasil! Consulte no site as Entidades beneficiadas! MVPConf.com.br
  5. 5. Patrocinadores
  6. 6. #MVPConf
  7. 7. #MVPConf Agenda The .NETCore .NET Foundation Jornada Open Source Aquisições EF Core 2.1 EFCore 2.2 EF Core 3.0 Demos
  8. 8. #MVPConf DESKTOP WEB CLOUD MOBILE GAMING IoT AI .NETCore Your platform for building anything
  9. 9. .NET ECOSYSTEM macOSiOS ASP.NET SignalR .NET SDK for Hadoop .NET Compiler Platform ("Roslyn") .NET Micro Framework ASP.NET MVC ASP.NET Web API ASP.NET Web Pages MVVM Light Toolkit .NET Core Orleans MEF OWIN Authentication Middleware Orchard CMS Microsoft Azure SDK for .NET IdentityManager Mimekit Xamarin.Auth Couchbase Lite for .NET Mailkit ASP.NET Core Salesforce Toolkits for .NET NuGet Kudu Cecil MSBuild LLILC Prism WorldWide Telescope ASP.NET AJAX Control Toolkit Entity Framework Microsoft Azure WebJobs SDK Microsoft Web Protection Library Open Live Writer Open XML SDK ProtoBuild System.Drawing IdentityServer Umbraco WCF Xamarin.Mobile Mono Xamarin SDK Cake Steeltoe Nancy xUnit DotNetNuke SourceLink nUnit MvvmCross IronPython ILMerge ML.NET Infer.NET JSON.NET
  10. 10. #MVPConf .NET 2001 ECMA 335 2002 NET 1.0 for Windows released. Mono project begins 2008 ASP.NET MVC (web platform) open source April 2014 .NET Compiler Platform (“Roslyn”) open source .NET Foundation founded Nov. 2014 .NET Core (cross-platform) project begins 2016 Mono project joins .NET Foundation Aug. 2017 .NET Core 2.0 released June 2018 .NET Core 2.1 released
  11. 11. #MVPConf Example: StringBuilder private static readonly StringBuilder s_builder = new StringBuilder(); public void StringBuilderAppend() { StringBuilder sb = s_builder; sb.Length = 0; for (int i = 0; i < 100_000; i++) sb.Append(i); } Toolchain Mean Allocated .NET Core 2.0 6.523 ms 3992000 B .NET Core 2.1 3.268 ms 0 B
  12. 12. #MVPConf Example: Strings public string StringToLowerChangesNeeded() => "This is a test to see what happens when we call ToLower.".ToLower(); public string StringToLowerAlreadyCased() => "this is a test to see what happens when we call tolower.".ToLower(); Method Toolchain Mean Allocated StringToLowerChangesNeeded .NET Core 2.0 187.00 ns 144 B StringToLowerChangesNeeded .NET Core 2.1 96.29 ns 144 B StringToLowerAlreadyCased .NET Core 2.0 197.21 ns 144 B StringToLowerAlreadyCased .NET Core 2.1 68.81 ns 0 B
  13. 13. #MVPConf Engenheiros do EFCore
  14. 14. #MVPConf EF Core 2.1 Major Features
  15. 15. #MVPConf EF Core 2.2 Major Features
  16. 16. #MVPConf Configurations Como funcionava até 2.1? http://ralms.net/dica/dicaapplyconfiguration/
  17. 17. #MVPConf Exemplo public class SampleDbContext : DbContext { public SampleDbContext(DbContextOptions<SampleDbContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.ApplyConfiguration(new LoginConfiguration()); modelBuilder.ApplyConfiguration(new ClienteConfiguration()); modelBuilder.ApplyConfiguration(new EnderecoConfiguration()); modelBuilder.ApplyConfiguration(new CidadeConfiguration()); modelBuilder.ApplyConfiguration(new ProdutoConfiguration()); modelBuilder.ApplyConfiguration(new EstoqueConfiguration()); modelBuilder.ApplyConfiguration(new ...); } }
  18. 18. #MVPConf Chuck Norris var mappingTypes = assembly .GetTypes() .Where(x => !x.IsAbstract && x.GetInterfaces() .Any(y => y.GetTypeInfo().IsGenericType && y.GetGenericTypeDefinition() == typeof(IEntityTypeConfiguration<>))); var entityMethod = typeof(ModelBuilder).GetMethods() .Single(x => x.Name == "Entity" && x.IsGenericMethod && x.ReturnType.Name == "EntityTypeBuilder`1"); foreach (var mappingType in mappingTypes) { var genericTypeArg = mappingType.GetInterfaces().Single().GenericTypeArguments.Single(); var genericEntityMethod = entityMethod.MakeGenericMethod(genericTypeArg); var entityBuilder = genericEntityMethod.Invoke(modelBuilder, null); var mapper = Activator.CreateInstance(mappingType); mapper.GetType().GetMethod("Configure").Invoke(mapper, new[] { entityBuilder }); }
  19. 19. #MVPConf Solução tabajara, perfeita! public class SampleDbContext : DbContext { public SampleDbContext(DbContextOptions<SampleDbContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder modelBuilder) { var assembly = typeof(SampleDbContext).Assembly; modelBuilder.ApplyConfigurationsFromAssembly(assembly); } }
  20. 20. #MVPConf Hint’s SQL With NOLOCK
  21. 21. Sorteios dos Brindes #MVPConf Clique Aqui para Iniciar o Sorteio Somente participarão dos sorteios os participantes que estiverem inscritos nas palestras e responderem as pesquisas de satisfação.
  22. 22. OBRIGADO #MVPConf YouTube.com/codereadybr LinkedIn.com/in/ralmsdeveloper Twitter.com /ralmsdeveloper Github.com/ralmsdeveloper .ralms.net THANKS!

×