Skip to content

Latest commit

 

History

History
179 lines (130 loc) · 4.57 KB

README.md

File metadata and controls

179 lines (130 loc) · 4.57 KB

EF Core Provider for «LCPI ADO.NET Provider for OLE DB» v6.0

Lcpi.EntityFrameworkCore.DataProvider.LcpiOleDb is an open source EF Core provider for «LCPI ADO.NET Provider for OLE DB».

Currently it allows you to interact with Firebird v3 via Microsoft Entity Framework Core v6.0.

Attention

This provider doesn't look and doesn't feel like any other Entity Framework Core provider.

Target platform

  1. NET6 (Windows)
  2. Entity Framework Core v6.0
  3. Firebird v3.0.8
  4. LCPI ADO.NET Provider for OLE DB
  5. LCPI.IBProvider v5

Key Features

  1. Supporting of databases with 1 and 3 dialects.
  2. Supporting of all FB3 datatypes, except arrays.
  3. Providing a local evaluation by server's rules.
  4. Supporting mapping wide set of c# functions to SQL.
  5. Providing extensions for nullable value types.

Limitations

  1. Restricted support of migrations.
  2. No support for database creation/dropping.

Example of usage

////////////////////////////////////////////////////////////////////////////////
//Please use correct TargetPlatform: net6.0-windows7.0
////////////////////////////////////////////////////////////////////////////////

using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

////////////////////////////////////////////////////////////////////////////////
//TEST TABLE

/*
RECREATE TABLE DBMS
(
 ID BIGINT GENERATED BY DEFAULT AS IDENTITY CONSTRAINT PK_DBMS PRIMARY KEY,

 NAME VARCHAR(32) CHARACTER SET UTF8,

 DESCRIPTION VARCHAR(128) CHARACTER SET UTF8
);
*/ 

////////////////////////////////////////////////////////////////////////////////

const string c_Dbms_Name ="Firebird";
const string c_Dbms_Descr="Of course I still \u2764 you! \ud83d\ude04"; // ;)
 
////////////////////////////////////////////////////////////////////////////////

try
{
 //---------------------------- INSERT
 Console.WriteLine("Inserting new record...");
 
 using var db=new MyDbContext();
 
 using var tr=db.Database.BeginTransaction();

 var newRecord=new DatabaseServer{ Name=c_Dbms_Name, Description=c_Dbms_Descr };
 
 db.DatabaseServers!.Add(newRecord);
 
 db.SaveChanges();
 
 var newRecordID=newRecord.ID;
 
 Console.WriteLine("newRecordID: {0}",newRecordID);
 
 //---------------------------- SELECT
 Console.WriteLine("Selecting inserted record...");
 
 var recs
  =db
   .DatabaseServers
   .Where(r => r.Description!.Length==c_Dbms_Descr.Length && r.ID==newRecordID)
   .Select(r => new {ServerName=r.Name!});
 
 int nRec=0;
 
 foreach(var r in recs)
 {
  ++nRec;
 
  Console.WriteLine("{0}. {1}",nRec, r.ServerName);
 }//foreach r

 if(nRec!=1)
  throw new ApplicationException("Oh sh...");
 
 //---------------------------- DELETE
 Console.WriteLine("Deleting inserted record...");
 
 db.DatabaseServers.Remove(newRecord);
 
 db.SaveChanges();

 tr.Commit();
}
catch(Exception ex)
{
 for(var e=ex;e!=null;e=e.InnerException)
 {
  Console.WriteLine
   ("--- ERROR: {0}\n{1}",
    e.Source,
    e.Message);
 }//for e
}//catch

// Cleanup ....
GC.Collect();
GC.WaitForPendingFinalizers();

////////////////////////////////////////////////////////////////////////////////

sealed class MyDbContext:DbContext
{
 private const string c_CnStr
  ="provider=LCPI.IBProvider.5;"
   +"location=inet4://localhost/d:\\database\\ram\\ibp_test_fb30_d3.gdb;"
   +"dbclient_type=fb.direct;"
   +"user id=SYSDBA;"
   +"password=masterkey;"
   +"auto_commit=true;"
   +"wchars_in_utf8_symbol=2;"; //Enabling full UTF8 support. Because we can.

 public DbSet<DatabaseServer>? DatabaseServers { get; set; }

 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
  optionsBuilder.UseLcpiOleDb(c_CnStr);
 }
};//class DbContext

////////////////////////////////////////////////////////////////////////////////

[Table("DBMS")]
sealed class DatabaseServer
{
 [Key]
 public long ID { get; set; }

 [Column("NAME", TypeName="VARCHAR(32) CHARACTER SET UTF8")]
 public string? Name { get; set; }

 [Column("DESCRIPTION", TypeName="VARCHAR(128) CHARACTER SET UTF8")]
 public string? Description { get; set; }
};//class DatabaseServer

////////////////////////////////////////////////////////////////////////////////

Output:

Inserting new record...
newRecordID: 8
Selecting inserted record...
1. Firebird
Deleting inserted record...

Related packages

See also