![]() |
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 Presto data through the CData ADO.NET Provider, providing you with more flexibility and control.
Accessing and integrating live data from Trino and Presto SQL engines has never been easier with CData. Customers rely on CData connectivity to:
Presto and Trino allow users to access a variety of underlying data sources through a single endpoint. When paired with CData connectivity, users get pure, SQL-92 access to their instances, allowing them to integrate business data with a data warehouse or easily access live data directly from their preferred tools, like Power BI and Tableau.
In many cases, CData's live connectivity surpasses the native import functionality available in tools. One customer was unable to effectively use Power BI due to the size of the datasets needed for reporting. When the company implemented the CData Power BI Connector for Presto they were able to generate reports in real-time using the DirectQuery connection mode.
Modify the App.config file in the project to add a reference to the Presto Entity Framework 6 assembly and the connection string.
Set the Server and Port connection properties to connect, in addition to any authentication properties that may be required.
To enable TLS/SSL, set UseSSL to true.
In order to authenticate with LDAP, set the following connection properties:
In order to authenticate with KERBEROS, set the following connection properties:
<configuration> ... <connectionStrings> <add name="PrestoContext" connectionString="Offline=False;Server=127.0.0.1;Port=8080;" providerName="System.Data.CData.Presto" /> </connectionStrings> <entityFramework> <providers> ... <provider invariantName="System.Data.CData.Presto" type="System.Data.CData.Presto.PrestoProviderServices, System.Data.CData.Presto.Entities.EF6" /> </providers> <entityFramework> </configuration> </code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class PrestoContext : DbContext {
public PrestoContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// To remove the requests to the Migration History table
Database.SetInitializer<PrestoContext>(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 FirstName { get; set; }
public System.String LastName { get; set; }
}
public DbSet<Customer> Customer { set; get; }
PrestoContext context = new PrestoContext(); context.Configuration.UseDatabaseNullSemantics = true; var query = from line in context.Customer select line;
Download a free trial of the Presto Data Provider to get started:
Download NowLearn more:
👁 Presto IconRapidly create and deploy powerful .NET applications that integrate with Presto.