Skip to content

Commit 4f2c8e9

Browse files
committed
Driver/C#: Add dedicated page
1 parent 5f5906b commit 4f2c8e9

File tree

4 files changed

+133
-0
lines changed

4 files changed

+133
-0
lines changed

docs/_assets/icon/csharp-logo.svg

Lines changed: 10 additions & 0 deletions
Loading

docs/_include/links.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
[ADBC]: https://arrow.apache.org/docs/format/ADBC.html
55
[Admin UI]: inv:crate-admin-ui:*:label#index
6+
[ADO.NET Overview]: https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/ado-net-overview
67
[Amazon DynamoDB Streams]: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.html
78
[Amazon Kinesis Data Streams]: https://docs.aws.amazon.com/streams/latest/dev/introduction.html
89
[Apache Airflow]: https://airflow.apache.org/
@@ -13,6 +14,7 @@
1314
[BM25]: https://en.wikipedia.org/wiki/Okapi_BM25
1415
[cloud-datashader-colab]: https://colab.research.google.com/github/crate/cratedb-examples/blob/amo/cloud-datashader/topic/timeseries/explore/cloud-datashader.ipynb
1516
[cloud-datashader-github]: https://github.com/crate/cratedb-examples/blob/amo/cloud-datashader/topic/timeseries/explore/cloud-datashader.ipynb
17+
[Connection Strings in ADO.NET]: https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/connection-strings
1618
[CTE]: inv:crate-reference#sql_dql_with
1719
[CrateDB BLOBs]: inv:crate-reference:*:label#blob_support
1820
[CrateDB Cloud]: inv:cloud:*:label#index

docs/connect/csharp.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
:::{include} /_include/links.md
2+
:::
3+
4+
(connect-csharp)=
5+
# C#
6+
7+
:::{div} sd-text-muted
8+
Connect to CrateDB from C# .NET applications.
9+
:::
10+
11+
:::{rubric} About
12+
:::
13+
14+
[Npgsql] is an open source ADO\.NET Data Provider for PostgreSQL, for programs
15+
written in C#, F#, or Visual Basic.
16+
17+
:::{rubric} Synopsis
18+
:::
19+
20+
`example.csproj`
21+
```xml
22+
<Project Sdk="Microsoft.NET.Sdk">
23+
24+
<PropertyGroup>
25+
<OutputType>Exe</OutputType>
26+
<TargetFramework>net$(NETCoreAppMaximumVersion)</TargetFramework>
27+
<GenerateProgramFile>false</GenerateProgramFile>
28+
</PropertyGroup>
29+
30+
<ItemGroup>
31+
<PackageReference Include="Npgsql" Version="10.0.0-rc.1" />
32+
</ItemGroup>
33+
34+
</Project>
35+
```
36+
`example.cs`
37+
```c#
38+
using Npgsql;
39+
using System;
40+
41+
// Connect to database.
42+
var connString = "Host=localhost;Port=5432;Username=crate;Password=crate;Database=doc;Sslmode=disable";
43+
var dataSourceBuilder = new NpgsqlDataSourceBuilder(connString);
44+
var dataSource = dataSourceBuilder.Build();
45+
var conn = dataSource.OpenConnection();
46+
47+
// Invoke basic query.
48+
var cmd = new NpgsqlCommand("SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3", conn);
49+
50+
// Display results.
51+
var reader = cmd.ExecuteReader();
52+
while (reader.Read())
53+
Console.WriteLine($"{reader.GetString(0)}: {reader.GetInt32(1)}");
54+
```
55+
56+
Start CrateDB using Docker or Podman, then invoke the example program.
57+
```shell
58+
docker run --rm --publish=5432:5432 crate '-Cdiscovery.type=single-node'
59+
```
60+
```shell
61+
export DOTNET_CLI_TELEMETRY_OPTOUT=true
62+
dotnet run
63+
```
64+
65+
:::{rubric} CrateDB Cloud
66+
:::
67+
68+
For connecting to CrateDB Cloud, use `Sslmode=require`, and
69+
replace hostname, username, and password with values matching
70+
your environment.
71+
```c#
72+
var connString = "Host=testcluster.cratedb.net;Port=5432;Username=admin;Password=password;Database=doc;Sslmode=require";
73+
```
74+
75+
## Examples
76+
77+
:::{card}
78+
:link: https://github.com/crate/cratedb-examples/tree/main/by-language/csharp-npgsql
79+
:link-type: url
80+
{material-outlined}`play_arrow;2em`
81+
Connect to CrateDB and CrateDB Cloud using .NET (C#)
82+
+++
83+
Demonstrates a basic example using Npgsql with CrateDB.
84+
:::
85+
86+
:::{card}
87+
:link: https://github.com/crate/cratedb-examples/tree/main/by-language/csharp-efcore
88+
:link-type: url
89+
{material-outlined}`play_arrow;2em`
90+
Connect to CrateDB and CrateDB Cloud using the Npgsql Entity Framework
91+
+++
92+
Demonstrates the Npgsql Entity Framework Core provider for PostgreSQL with CrateDB.
93+
:::
94+
95+
[![C# Npgsql](https://github.com/crate/cratedb-examples/actions/workflows/lang-csharp-npgsql.yml/badge.svg)](https://github.com/crate/cratedb-examples/actions/workflows/lang-csharp-npgsql.yml)
96+
[![C# EF Core](https://github.com/crate/cratedb-examples/actions/workflows/lang-csharp-efcore.yml/badge.svg)](https://github.com/crate/cratedb-examples/actions/workflows/lang-csharp-efcore.yml)
97+
98+
## See also
99+
100+
:::{div}
101+
- [Connection Strings in ADO.NET]
102+
- [ADO.NET Overview]
103+
:::
104+
105+
106+
[Npgsql]: https://www.npgsql.org/

docs/connect/index.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ CrateDB drivers and adapters for supported programming languages, frameworks, an
4949
:margin: 4 4 0 0
5050
:padding: 0
5151

52+
::::{grid-item-card} C#
53+
:link: connect-csharp
54+
:link-type: ref
55+
:link-alt: Connect to CrateDB using C#
56+
:padding: 3
57+
:text-align: center
58+
:class-card: sd-pt-3
59+
:class-body: sd-fs-1
60+
:class-title: sd-fs-6
61+
```{image} /_assets/icon/csharp-logo.svg
62+
:height: 50px
63+
```
64+
::::
65+
5266
::::{grid-item-card} Java
5367
:link: connect-java
5468
:link-type: ref
@@ -182,6 +196,7 @@ application
182196
:maxdepth: 1
183197
:hidden:
184198
199+
csharp
185200
java
186201
javascript
187202
php

0 commit comments

Comments
 (0)