![]() |
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 Google Data Catalog 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 Google Data Catalog Entity Framework 6 assembly and the connection string.
Google Data Catalog uses the OAuth authentication standard. Authorize access to Google APIs on behalf on individual users or on behalf of users in a domain.
Before connecting, specify the following to identify the organization and project you would like to connect to:
Click the project selection drop-down, and select your organization from the list. Then, click More -> Settings. The organization ID is displayed on this page.
Find this by navigating to the cloud console dashboard and selecting your project from the Select from drop-down. The project ID will be present in the Project info card.
When you connect, the OAuth endpoint opens in your default browser. Log in and grant permissions to the application to completes the OAuth process. For more information, refer to the OAuth section in the Help documentation.
<configuration> ... <connectionStrings> <add name="GoogleDataCatalogContext" connectionString="Offline=False;ProjectId=YourProjectId;InitiateOAuth=GETANDREFRESH;" providerName="System.Data.CData.GoogleDataCatalog" /> </connectionStrings> <entityFramework> <providers> ... <provider invariantName="System.Data.CData.GoogleDataCatalog" type="System.Data.CData.GoogleDataCatalog.GoogleDataCatalogProviderServices, System.Data.CData.GoogleDataCatalog.Entities.EF6" /> </providers> <entityFramework> </configuration> </code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class GoogleDataCatalogContext : DbContext {
public GoogleDataCatalogContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// To remove the requests to the Migration History table
Database.SetInitializer<GoogleDataCatalogContext>(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("Schemas")]
public class Schemas {
[System.ComponentModel.DataAnnotations.Key]
public System.String Type { get; set; }
public System.String DatasetName { get; set; }
}
public DbSet<Schemas> Schemas { set; get; }
GoogleDataCatalogContext context = new GoogleDataCatalogContext(); context.Configuration.UseDatabaseNullSemantics = true; var query = from line in context.Schemas select line;
Download a free trial of the Google Data Catalog Data Provider to get started:
Download NowLearn more:
👁 Google Data Catalog IconRapidly create and deploy powerful .NET applications that integrate with Google Data Catalog.