Skip to content

Commit 096175b

Browse files
committed
Basic docs
1 parent 63456df commit 096175b

File tree

3 files changed

+191
-0
lines changed

3 files changed

+191
-0
lines changed

Provider/docs/ado-net.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# ADO.NET
2+
3+
### Steps
4+
5+
* Install `FirebirdSql.Data.FirebirdClient` from NuGet.
6+
* Add `using FirebirdSql.Data.FirebirdClient;`.
7+
* Basic classes are `FbConnection`, `FbTransaction`, `FbCommand` and `FbDataReader`.
8+
* Connection string can be built using `FbConnectionStringBuilder`.
9+
10+
### Code
11+
12+
```csharp
13+
using (var connection = new FbConnection("database=localhost:demo.fdb;user=sysdba;password=masterkey"))
14+
{
15+
connection.Open();
16+
using (var transaction = connection.BeginTransaction())
17+
{
18+
using (var command = new FbCommand("select * from demo", connection, transaction))
19+
{
20+
using (var reader = command.ExecuteReader())
21+
{
22+
while (reader.Read())
23+
{
24+
var values = new object[reader.FieldCount];
25+
reader.GetValues(values);
26+
Console.WriteLine(string.Join("|", values));
27+
}
28+
}
29+
}
30+
}
31+
}
32+
```
33+
34+
### Scripts
35+
36+
```sql
37+
create table demo (id int primary key, foobar varchar(20) character set utf8);
38+
```
39+
40+
```sql
41+
insert into demo values (6, 'FooBar');
42+
```

Provider/docs/entity-framework-6.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Entity Framework 6
2+
3+
### Steps
4+
5+
* Install `EntityFramework.Firebird` from NuGet.
6+
* Add `DbProviderFactories` record.
7+
```xml
8+
<system.data>
9+
<DbProviderFactories>
10+
<remove invariant="FirebirdSql.Data.FirebirdClient" />
11+
<add name="FirebirdClient" description="FirebirdClient" invariant="FirebirdSql.Data.FirebirdClient" type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient" />
12+
</DbProviderFactories>
13+
</system.data>
14+
```
15+
* Add/modify `entityFramework` configuration section.
16+
```xml
17+
<configSections>
18+
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
19+
</configSections>
20+
<entityFramework>
21+
<defaultConnectionFactory type="EntityFramework.Firebird.FbConnectionFactory, EntityFramework.Firebird" />
22+
<providers>
23+
<provider invariantName="FirebirdSql.Data.FirebirdClient" type="EntityFramework.Firebird.FbProviderServices, EntityFramework.Firebird" />
24+
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
25+
</providers>
26+
</entityFramework>
27+
```
28+
* Create your `DbContext`.
29+
30+
### Code
31+
32+
```csharp
33+
class Program
34+
{
35+
static void Main(string[] args)
36+
{
37+
using (var db = new MyContext("database=localhost:demo.fdb;user=sysdba;password=masterkey"))
38+
{
39+
db.Database.Log = Console.WriteLine;
40+
41+
db.Demos.ToList();
42+
}
43+
}
44+
}
45+
46+
class MyContext : DbContext
47+
{
48+
public MyContext(string connectionString)
49+
: base(new FbConnection(connectionString), true)
50+
{ }
51+
52+
public DbSet<Demo> Demos { get; set; }
53+
54+
protected override void OnModelCreating(DbModelBuilder modelBuilder)
55+
{
56+
base.OnModelCreating(modelBuilder);
57+
58+
modelBuilder.Properties()
59+
.Configure(x => x.HasColumnName(x.ClrPropertyInfo.Name.ToUpper()));
60+
61+
var demoConf = modelBuilder.Entity<Demo>();
62+
demoConf.ToTable("DEMO");
63+
}
64+
}
65+
66+
class Demo
67+
{
68+
public int Id { get; set; }
69+
public string FooBar { get; set; }
70+
}
71+
```
72+
73+
### Scripts
74+
75+
```sql
76+
create table demo (id int primary key, foobar varchar(20) character set utf8);
77+
```
78+
79+
```sql
80+
insert into demo values (6, 'FooBar');
81+
```
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Entity Framework Core 2.0 and higher
2+
3+
* Install `FirebirdSql.EntityFrameworkCore.Firebird` from NuGet.
4+
* Add `using FirebirdSql.EntityFrameworkCore.Firebird.Extensions;`.
5+
* Create your `DbContext`.
6+
* Call `UseFirebird` in `OnConfiguring`.
7+
8+
### Code
9+
10+
```csharp
11+
class Program
12+
{
13+
static void Main(string[] args)
14+
{
15+
using (var db = new MyContext("database=localhost:demo.fdb;user=sysdba;password=masterkey"))
16+
{
17+
db.GetService<ILoggerFactory>().AddConsole();
18+
19+
db.Demos.ToList();
20+
}
21+
}
22+
}
23+
24+
class MyContext : DbContext
25+
{
26+
readonly string _connectionString;
27+
28+
public MyContext(string connectionString)
29+
{
30+
_connectionString = connectionString;
31+
}
32+
33+
public DbSet<Demo> Demos { get; set; }
34+
35+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
36+
{
37+
base.OnConfiguring(optionsBuilder);
38+
39+
optionsBuilder.UseFirebird(_connectionString);
40+
}
41+
42+
protected override void OnModelCreating(ModelBuilder modelBuilder)
43+
{
44+
base.OnModelCreating(modelBuilder);
45+
46+
var demoConf = modelBuilder.Entity<Demo>();
47+
demoConf.Property(x => x.Id).HasColumnName("ID");
48+
demoConf.Property(x => x.FooBar).HasColumnName("FOOBAR");
49+
demoConf.ToTable("DEMO");
50+
}
51+
}
52+
53+
class Demo
54+
{
55+
public int Id { get; set; }
56+
public string FooBar { get; set; }
57+
}
58+
```
59+
60+
### Scripts
61+
62+
```sql
63+
create table demo (id int primary key, foobar varchar(20) character set utf8);
64+
```
65+
66+
```sql
67+
insert into demo values (6, 'FooBar');
68+
```

0 commit comments

Comments
 (0)