Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
67 lines (52 sloc) 1.3 KB

Entity Framework Core 2.x

  • Install FirebirdSql.EntityFrameworkCore.Firebird from NuGet.
  • Create your DbContext.
  • Call UseFirebird in OnConfiguring.

Code

class Program
{
    static void Main(string[] args)
    {
		using (var db = new MyContext("database=localhost:demo.fdb;user=sysdba;password=masterkey"))
		{
			db.GetService<ILoggerFactory>().AddConsole();

			db.Demos.ToList();
		}
	}
}

class MyContext : DbContext
{
	readonly string _connectionString;

	public MyContext(string connectionString)
	{
		_connectionString = connectionString;
	}

	public DbSet<Demo> Demos { get; set; }

	protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
	{
		base.OnConfiguring(optionsBuilder);

		optionsBuilder.UseFirebird(_connectionString);
	}

	protected override void OnModelCreating(ModelBuilder modelBuilder)
	{
		base.OnModelCreating(modelBuilder);

		var demoConf = modelBuilder.Entity<Demo>();
		demoConf.Property(x => x.Id).HasColumnName("ID");
		demoConf.Property(x => x.FooBar).HasColumnName("FOOBAR");
		demoConf.ToTable("DEMO");
	}
}

class Demo
{
	public int Id { get; set; }
	public string FooBar { get; set; }
}

Scripts

create table demo (id int primary key, foobar varchar(20) character set utf8);
insert into demo values (6, 'FooBar');
You can’t perform that action at this time.