![]() |
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 SAS Data Sets 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 SAS Data Sets Entity Framework 6 assembly and the connection string.
Set the following connection properties to connect to your SAS DataSet files:
While the driver is capable of pulling data from SAS DataSet files hosted on a variety of cloud data stores, INSERT, UPDATE, and DELETE are not supported outside of local files in this driver.
Set the Connection Type to the service hosting your SAS DataSet files. A unique prefix at the beginning of the URI connection property is used to identify the cloud data store and the remainder of the path is a relative path to the desired folder (one table per file) or single file (a single table). For more information, refer to the Getting Started section of the Help documentation.
<configuration> ... <connectionStrings> <add name="SASDataSetsContext" connectionString="Offline=False;URI=C:/myfolder;" providerName="System.Data.CData.SASDataSets" /> </connectionStrings> <entityFramework> <providers> ... <provider invariantName="System.Data.CData.SASDataSets" type="System.Data.CData.SASDataSets.SASDataSetsProviderServices, System.Data.CData.SASDataSets.Entities.EF6" /> </providers> <entityFramework> </configuration> </code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class SASDataSetsContext : DbContext {
public SASDataSetsContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// To remove the requests to the Migration History table
Database.SetInitializer<SASDataSetsContext>(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("restaurants")]
public class restaurants {
[System.ComponentModel.DataAnnotations.Key]
public System.String name { get; set; }
public System.String borough { get; set; }
}
public DbSet<restaurants> restaurants { set; get; }
SASDataSetsContext context = new SASDataSetsContext(); context.Configuration.UseDatabaseNullSemantics = true; var query = from line in context.restaurants select line;
Download a free trial of the SAS Data Sets Data Provider to get started:
Download NowLearn more:
👁 SAS Data Sets IconRapidly create and deploy powerful .NET applications that integrate with SAS Data Sets.