![]() |
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 SQL 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 SQL Analysis Services Entity Framework 6 assembly and the connection string.
To connect, provide authentication and set the Url property to a valid SQL Server Analysis Services endpoint. You can connect to SQL Server Analysis Services instances hosted over HTTP with XMLA access. See the Microsoft documentation to configure HTTP access to SQL Server Analysis Services.
To secure connections and authenticate, set the corresponding connection properties, below. The data provider supports the major authentication schemes, including HTTP and Windows, as well as SSL/TLS.
Set AuthScheme to "Basic" or "Digest" and set User and Password. Specify other authentication values in CustomHeaders.
Set the Windows User and Password and set AuthScheme to "NTLM".
To authenticate with Kerberos, set AuthScheme to NEGOTIATE. To use Kerberos delegation, set AuthScheme to KERBEROSDELEGATION. If needed, provide the User, Password, and KerberosSPN. By default, the data provider attempts to communicate with the SPN at the specified Url.
By default, the data provider attempts to negotiate SSL/TLS by checking the server's certificate against the system's trusted certificate store. To specify another certificate, see the SSLServerCert property for the available formats.
You can then access any cube as a relational table: When you connect the data provider retrieves SSAS metadata and dynamically updates the table schemas. Instead of retrieving metadata every connection, you can set the CacheLocation property to automatically cache to a simple file-based store.
See the Getting Started section of the CData documentation, under Retrieving Analysis Services Data, to execute SQL-92 queries to the cubes.
<configuration> ... <connectionStrings> <add name="SSASContext" connectionString="Offline=False;User=myuseraccount;Password=mypassword;URL=http://localhost/OLAP/msmdpump.dll;" providerName="System.Data.CData.SSAS" /> </connectionStrings> <entityFramework> <providers> ... <provider invariantName="System.Data.CData.SSAS" type="System.Data.CData.SSAS.SSASProviderServices, System.Data.CData.SSAS.Entities.EF6" /> </providers> <entityFramework> </configuration> </code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class SSASContext : DbContext {
public SSASContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// To remove the requests to the Migration History table
Database.SetInitializer<SSASContext>(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("Adventure_Works")]
public class Adventure_Works {
[System.ComponentModel.DataAnnotations.Key]
public System.String Fiscal_Year { get; set; }
public System.String Sales_Amount { get; set; }
}
public DbSet<Adventure_Works> Adventure_Works { set; get; }
SSASContext context = new SSASContext(); context.Configuration.UseDatabaseNullSemantics = true; var query = from line in context.Adventure_Works select line;
Download a free trial of the SQL Analysis Services Data Provider to get started:
Download NowLearn more:
👁 SQL Server Analysis Services IconRapidly create and deploy powerful .NET applications that integrate with SQL Analysis Services.