![]() |
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 Analysis Services 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 Analysis Services Entity Framework 6 assembly and the connection string.
To connect to Azure Analysis Services, set the Url property to a valid server, for instance, asazure://southcentralus.asazure.windows.net/server, in addition to authenticating. Optionally, set Database to distinguish which Azure database on the server to connect to.
Azure Analysis Services uses the OAuth authentication standard. OAuth requires the authenticating user to interact with Azure Analysis Services using the browser. You can connect without setting any connection properties for your user credentials. See the Help documentation for more information.
<configuration> ... <connectionStrings> <add name="AASContext" connectionString="Offline=False;URL=asazure://REGION.asazure.windows.net/server;InitiateOAuth=GETANDREFRESH;" providerName="System.Data.CData.AAS" /> </connectionStrings> <entityFramework> <providers> ... <provider invariantName="System.Data.CData.AAS" type="System.Data.CData.AAS.AASProviderServices, System.Data.CData.AAS.Entities.EF6" /> </providers> <entityFramework> </configuration> </code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class AASContext : DbContext {
public AASContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// To remove the requests to the Migration History table
Database.SetInitializer<AASContext>(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("Customer")]
public class Customer {
[System.ComponentModel.DataAnnotations.Key]
public System.String Country { get; set; }
public System.String Education { get; set; }
}
public DbSet<Customer> Customer { set; get; }
AASContext context = new AASContext(); context.Configuration.UseDatabaseNullSemantics = true; var query = from line in context.Customer select line;
Download a free trial of the Azure Analysis Services Data Provider to get started:
Download NowLearn more:
👁 Azure Analysis Services IconRapidly create and deploy powerful .NET applications that integrate with Azure Analysis Services.