using System; using System.Linq; using FirebirdSql.Data.FirebirdClient; using Microsoft.EntityFrameworkCore; namespace ConsoleApp85 { internal class Program { static void Main(string[] args) { using (var fooContext = new FooContext("C:\\rfa\\dummyDb.fdb")) { fooContext.Database.EnsureDeleted(); fooContext.Database.EnsureCreated(); } using (var fooContext = new FooContext("C:\\rfa\\dummyDb.fdb")) { fooContext.Foos.Add(new Foo() { FooId = 1, FooText = "Hello World 1", FooValue = 1 }); fooContext.Foos.Add(new Foo() { FooId = 2, FooText = "Hello World 2", FooValue = 2 }); fooContext.Foos.Add(new Foo() { FooId = 3, FooText = "Hello World 3", FooValue = 3 }); fooContext.SaveChanges(); } using (var fooContext = new FooContext("C:\\rfa\\dummyDb.fdb")) { var dbConnection = fooContext.Database.GetDbConnection(); dbConnection.Open(); using var dbCommand = dbConnection.CreateCommand(); dbCommand.CommandText = "select sum(foovalue) from foo"; Console.WriteLine(dbCommand.ExecuteScalar()); } Console.ReadLine(); } } public class FooContext : DbContext { private readonly string _conString; public DbSet Foos { get; set; } public FooContext(string dbPath) { var fb = new FbConnectionStringBuilder() { UserID = "", Password = "", DataSource = "localhost", Port = 3052, Database = dbPath, }; _conString = fb.ToString(); } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { base.OnConfiguring(optionsBuilder); if (!string.IsNullOrEmpty(_conString)) { optionsBuilder .UseFirebird(_conString, x => x.WithExplicitParameterTypes(false).WithExplicitStringLiteralTypes(false)); } } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); var entityConf = modelBuilder.Entity(); entityConf.Property(x => x.FooId).HasColumnName("FOOID"); entityConf.Property(x => x.FooText).HasColumnName("FOOTEXT"); entityConf.Property(x => x.FooValue).HasColumnName("FOOVALUE"); entityConf.HasKey(x => x.FooId); entityConf.ToTable("FOO"); } } public class Foo { public int FooId { get; set; } public string FooText { get; set; } public decimal FooValue { get; set; } } }