Entity Framework 6
repository·main·Indexed 23 days ago
https://github.com/dotnet/ef6A mature object-relational mapper (ORM) for .NET that maps objects to relational database structures. EF6 is currently in maintenance mode, focusing on stability and security fixes for .NET Framework and .NET Core applications. It supports Visual Designer and EDMX files, and includes providers for SQL Server Compact 4.0 and a modern Microsoft.Data.SqlClient-based SQL Server provider.
What's inside EF6
- Entity Framework 6 (EF6) is an object-relational mapper (ORM) for .NET. It is designed to eliminate the need for much of the boilerplate data-access code typically required when interacting with databases by mapping objects to relational database structures.
Use SQL Server Compact 4.0 with Entity Framework
mainThis provider allows you to use SQL Server Compact 4.0 as a data store with Entity Framework 6. It enables EF6 to interact with.sdfdatabase files using the SQL Server Compact engine.Use the `templateIs1ESManaged` parameter
mainThe
templateIs1ESManagedparameter is available on most templates and determines which variant of nested templates is used.Requirement: For templates located under
job/,jobs/,steps, orpost-build/, you must explicitly set this parameter.Choose between EF6 and EF Core
mainWhen deciding whether to use EF6 or EF Core, consider the following differences:
Feature Entity Framework 6 (EF6) Entity Framework Core (EF Core) Development Status Maintenance mode (stable) Actively developed Target Runtime .NET Framework and .NET Core Modern .NET only (does not run on .NET Framework) Architecture Supports Visual Designer and EDMX files Lightweight, extensible, no Visual Designer/EDMX Performance Established/Stable Includes many improvements and new features If you are starting a new project on modern .NET, EF Core is the recommended path. If you have an existing EF6 project, you can follow the Port from EF6 to EF Core guide to migrate.
Understand the support status of EF6
mainEF6 is in a maintenance mode and is no longer under active feature development.
What to expect:
- Security: Security issues will be fixed.
- Bugs: High-impact bugs (affecting a large number of users) may be fixed, but most other bugs will not be addressed.
- Features: No new features will be implemented.
- Stability: The focus is on codebase stability and compatibility with new versions of the .NET ecosystem.
- Contributions: Community pull requests are not being accepted to ensure maximum stability.
Use the provider with EDMX files
mainTo use this provider with an EDMX model, you must update the provider name in two locations.
Warning: To use the Visual Studio designer, you must temporarily switch the provider name back to
System.Data.SqlClient.<!-- 1. Update the StorageModel Schema Provider --> <edmx:Edmx Version="3.0" xmlns:edmx="http://schemas.microsoft.com/ado/2009/11/edmx"> <edmx:Runtime> <edmx:StorageModels> <Schema Namespace="ChinookModel.Store" Provider="Microsoft.Data.SqlClient" > <!-- 2. Update the EntityConnection connection string provider --> <add name="Database" connectionString="metadata=res://*/EFModels.csdl|res://*/EFModels.ssdl|res://*/EFModels.msl;provider=Microsoft.Data.SqlClient;provider connection string=\"data source=server;initial catalog=mydb;integrated security=True;persist security info=True;\"" providerName="System.Data.EntityClient" />Access EF6 documentation and support
mainFor installation guides, tutorials, samples, and full documentation, visit the official EF6 docs.
Note on Support:
- The EF team is primarily focused on EF Core and is unlikely to respond to issues filed in the EF6 repository.
- For community help, use Stack Overflow with the
entity-frameworktag. - For professional assistance, you can contact a Microsoft Support professional (fees may apply).
Reduce security scan overhead using Multiple Outputs
mainWhen using 1ES pipeline templates (
templates-official), every publish artifact execution triggers additional security scans. To reduce this overhead, you can use theoutputParentDirectoryfeature to gather all publishing outputs into the$(Build.ArtifactStagingDirectory)and utilize thetemplateContext.outputsparameter.Implementation Steps:
- Ensure all build artifacts are copied to
$(Build.ArtifactStagingDirectory)using a task likeCopyFiles@2. - Define your outputs within the
templateContextblock in your job template.
Note: Multiple outputs are only applicable to 1ES PT publishing (when referencing
templates-official).# azure-pipelines.yml extends: template: azure-pipelines/MicroBuild.1ES.Official.yml@MicroBuildTemplate parameters: stages: - stage: build jobs: - template: /eng/common/templates-official/jobs/jobs.yml@self parameters: # 1ES makes use of outputs to reduce security task injection overhead templateContext: outputs: - output: pipelineArtifact displayName: 'Publish logs from source' continueOnError: true condition: always() targetPath: $(Build.ArtifactStagingDirectory)/artifacts/log artifactName: Logs jobs: - job: Windows steps: - script: echo "friendly neighborhood" > artifacts/marvel/spiderman.txt # copy build outputs to artifact staging directory for publishing - task: CopyFiles@2 displayName: Gather build output inputs: SourceFolder: '$(System.DefaultWorkingDirectory)/artifacts/marvel' Contents: '**' TargetFolder: '$(Build.ArtifactStagingDirectory)/artifacts/marvel'- Ensure all build artifacts are copied to
Install the Entity Framework 6 SQL Server provider
mainThis provider is a replacement for the built-in SQL Server provider in Entity Framework 6. It is based on the modern
Microsoft.Data.SqlClientADO.NET provider, offering support for SQL Server 2022 (TDS8), Azure Active Directory authentication, and Always Encrypted.Note: This is a runtime-only update and is not compatible with existing Visual Studio tooling (like the EDMX designer).
Migrate code to the Microsoft.Data.SqlClient provider
mainWhen switching from the built-in provider to this one, perform the following updates in your codebase:
Namespace Changes
- Replace
using System.Data.SqlClient;withusing Microsoft.Data.SqlClient; - Replace
using Microsoft.SqlServer.Server;withusing Microsoft.Data.SqlClient.Server;
Renamed Classes
The following classes have been renamed to avoid conflicts with the legacy
System.Data.SqlClientprovider:Old Name New Name SqlAzureExecutionStrategyMicrosoftSqlAzureExecutionStrategySqlDbConfigurationMicrosoftSqlDbConfigurationSqlProviderServicesMicrosoftSqlProviderServicesSqlServerMigrationSqlGeneratorMicrosoftSqlServerMigrationSqlGeneratorSqlSpatialServicesMicrosoftSqlSpatialServicesSqlConnectionFactoryMicrosoftSqlConnectionFactoryLocalDbConnectionFactoryMicrosoftLocalDbConnectionFactory- Replace
Configure the Microsoft SQL Server provider in code
mainYou can register the new provider using one of the following three methods:
1. Using the
[DbConfigurationType]attributeApply this attribute to your
DbContextclass. If you have multipleDbContextclasses, you must apply it to all of them.2. Using
DbConfiguration.SetConfigurationCall this method before any data access occurs in your application.
3. Extending an existing
DbConfigurationclassIf you already have a custom
DbConfigurationclass, add the following lines to map the provider names to theMicrosoft.Data.SqlClientimplementation.Use Entity Framework Migrations cmdlets
mainEntity Framework Migrations allow you to manage database schema changes using a Code First approach. Use the following cmdlets within the Package Manager Console to manage your migrations lifecycle:
Enable-Migrations: Initializes Code First Migrations in your project.Add-Migration <MigrationName>: Scaffolds a new migration script based on any pending changes in your model.Update-Database: Applies any pending migrations to the target database.Get-Migrations: Lists the migrations that have already been applied to the target database.