![]() |
VOOZH | about |
Microsoft Entity Framework serves as an object-relational mapping framework for working with data represented as objects. Although Visual Studio offers the ADO.NET Entity Data Model wizard to automatically generate the Entity Model, this model-first approach may present challenges when your data source undergoes changes or when you require greater control over entity operations. In this article, we will delve into the code-first approach for accessing Azure Data Lake Storage data through the CData ADO.NET Provider, providing you with more flexibility and control.
Modify the App.config file in the project to add a reference to the Azure Data Lake Storage Entity Framework 6 assembly and the connection string.
Gen 1 uses OAuth 2.0 in Entra ID (formerly Azure AD) for authentication.
For this, an Active Directory web application is required. You can create one as follows:
To authenticate against a Gen 1 DataLakeStore account, the following properties are required:
To authenticate against a Gen 2 DataLakeStore account, the following properties are required:
<configuration> ... <connectionStrings> <add name="ADLSContext" connectionString="Offline=False;Schema=ADLSGen2;Account=myAccount;FileSystem=myFileSystem;AccessKey=myAccessKey;InitiateOAuth=GETANDREFRESH;" providerName="System.Data.CData.ADLS" /> </connectionStrings> <entityFramework> <providers> ... <provider invariantName="System.Data.CData.ADLS" type="System.Data.CData.ADLS.ADLSProviderServices, System.Data.CData.ADLS.Entities.EF6" /> </providers> <entityFramework> </configuration> </code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class ADLSContext : DbContext {
public ADLSContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// To remove the requests to the Migration History table
Database.SetInitializer<ADLSContext>(null);
// To remove the plural names
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations.Schema;
[System.ComponentModel.DataAnnotations.Schema.Table("Resources")]
public class Resources {
[System.ComponentModel.DataAnnotations.Key]
public System.String FullPath { get; set; }
public System.String Permission { get; set; }
}
public DbSet<Resources> Resources { set; get; }
ADLSContext context = new ADLSContext(); context.Configuration.UseDatabaseNullSemantics = true; var query = from line in context.Resources select line;
Download a free trial of the Azure Data Lake Storage Data Provider to get started:
Download NowLearn more:
👁 Azure Data Lake Storage IconRapidly create and deploy powerful .NET applications that integrate with Azure Data Lake Storage.