![]() |
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 REST 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 REST Entity Framework 6 assembly and the connection string.
See the Getting Started chapter in the data provider documentation to authenticate to your data source: The data provider models REST APIs as bidirectional database tables and XML/JSON files as read-only views (local files, files stored on popular cloud services, and FTP servers). The major authentication schemes are supported, including HTTP Basic, Digest, NTLM, OAuth, and FTP. See the Getting Started chapter in the data provider documentation for authentication guides.
After setting the and providing any authentication values, set to "XML" or "JSON" and set to more closely match the data representation to the structure of your data.
The property is the controlling property over how your data is represented into tables and toggles the following basic configurations.
See the Modeling REST Data chapter for more information on configuring the relational representation. You will also find the sample data used in the following examples. The data includes entries for people, the cars they own, and various maintenance services performed on those cars.
<configuration> ... <connectionStrings> <add name="RESTContext" connectionString="Offline=False;DataModel=Relational;URI=C:/people.xml;Format=XML;" providerName="System.Data.CData.REST" /> </connectionStrings> <entityFramework> <providers> ... <provider invariantName="System.Data.CData.REST" type="System.Data.CData.REST.RESTProviderServices, System.Data.CData.REST.Entities.EF6" /> </providers> <entityFramework> </configuration> </code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class RESTContext : DbContext {
public RESTContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// To remove the requests to the Migration History table
Database.SetInitializer<RESTContext>(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("people")]
public class people {
[System.ComponentModel.DataAnnotations.Key]
public System.String [ personal.name.first ] { get; set; }
public System.String [ personal.name.last ] { get; set; }
}
public DbSet<people> people { set; get; }
RESTContext context = new RESTContext(); context.Configuration.UseDatabaseNullSemantics = true; var query = from line in context.people select line;
Download a free trial of the REST Data Provider to get started:
Download NowLearn more:
👁 REST IconRapidly create and deploy powerful .NET applications that integrate with REST web services.