Entity Framework Core Provider for Progress OpenEdge

https://github.com/alexwiese/EntityFrameworkCore.OpenEdge

You can now use Entity Framework Core with Progress OpenEdge via ODBC.

Install it from Nuget

Install-Package EntityFrameworkCore.OpenEdge -Version 1.0.2

Then wire up the provider with your ODBC Connection string in the DbContext.

public class MyDbContext : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseOpenEdge("dsn=MyDb;password=mypassword");
    }
}

It even works with LINQPad with the Entity Framework Core LINQPad driver

Using Dapper with a Progress OpenEdge database

This is part 1 in a two-part series of blog posts about using Dapper with Progress OpenEdge.

Part 2 (coming soon) talks about using Dapper.Contrib with OpenEdge.

What is Dapper?

Dapper is a lightweight, open-source ORM for the .NET Framework that provides extension methods for the IDbConnection interface.

It allows you to easily execute SQL statements and map the results to objects, and more.

Example:

public class Dog
{
    public int Id { get; set; }
    public int? Age { get; set; }
    public string Name { get; set; }
    public float? Weight { get; set; }
}

var dogs = connection.Query<Dog>("select * from dbo.Dog");

Using the Progress OpenEdge ODBC Driver

To connect to the OpenEdge database from .NET I am using the Progress OpenEdge 11.6 ODBC Driver which is included in Progress OpenEdge 11.6. This is a 32-bit only driver which means we must open the 32-bit ODBC Data Source Administration console within Windows.

Adding an ODBC System DSN

To use the ODBC driver we need to create a System Data Source. The first step is to select the driver we want to use.

Next, I enter in my data source name, description, and database connection settings.

Ensure you use the port number for the OpenEdge SQL broker, not the 4GL broker

Once the ODBC Data Source is created you can now use it from .NET using the Data Source Name from the previous step. Here I am selecting all records from the Dogs table and printing the Ids.

using (var connection = new OdbcConnection("DSN=My OpenEdge DB;Pwd=mypassword"))
{
    connection.Open();

    var command = connection.CreateCommand();
    command.CommandText = "SELECT * FROM pub.Dogs";

    var reader = command.ExecuteReader();

    while (reader.Read())
    {
        Console.WriteLine(reader.GetInt32(0));
    }
}

Wiring it all up

Because OdbcConnection implements the IDbConnection interface we can use it directly with Dapper.

using (var connection = new OdbcConnection("DSN=My OpenEdge DB;Pwd=mypassword"))
{
    connection.Open();

    var dogs = connection.Query<Dog>("SELECT * FROM pub.Dogs");
}

I have now selected all records from the Dogs table and used them to populate a List<Dog>.

Here’s the output in LINQPad:

This code can now be extended to query the database for different records, and more complex SQL queries.

Part 2 (coming soon) talks about using Dapper.Contrib to dynamically generate SQL statements instead of having to hand-craft them.