OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Connector/NET

V1.1.0

  • What Is OceanBase Connector/NET
    • Introduction
  • Install and Connect
    • Installation process
    • Test the connection
    • Package reference and usage
    • Compatibility impact
  • User Guide
    • Quick Start
      • Complete example
    • Connection Strings and Data Source
      • Connection strings
    • Data Types
      • Overview of data types
    • Command and Parameter
      • Overview
    • Result Set
      • Supported result set types
    • ORM and Frameworks
      • Use Entity Framework Core
      • Use SqlSugar
      • Use FreeSql
  • Reference Information
    • Common Interfaces
      • Overview of commonly used interfaces
  • Version Release Records
    • OceanBase Connector/NET V1.0.0
    • OceanBase Connector/NET V1.1.0

Download PDF

Introduction Installation process Test the connection Package reference and usage Compatibility impact Complete example Connection strings Overview of data types Overview Supported result set types Use Entity Framework Core Use SqlSugar Use FreeSql Overview of commonly used interfaces OceanBase Connector/NET V1.0.0 OceanBase Connector/NET V1.1.0
OceanBase logo

The Unified Distributed Database for the AI Era.

Follow Us
Products
OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
Resources
DocsBlogLive DemosTraining & Certification
Company
About OceanBaseTrust CenterLegalPartnerContact Us
Follow Us

© OceanBase 2026. All rights reserved

Cloud Service AgreementPrivacy PolicySecurity
Contact Us
Document Feedback
  1. Documentation Center
  2. OceanBase Connector/NET
  3. V1.1.0
iconOceanBase Connector/NET
V 1.1.0
  • V 1.1.0
  • V 1.0.0

Use FreeSql

Last Updated:2026-04-28 03:38:03  Updated
share
What is on this page
Installation
Connection string
Quick start
Full example
Read/write separation example
Native SQL example
CodeFirst / DbFirst
CodeFirst
DbFirst
Recommended Integration Approach
Considerations
Minimum Connectivity Verification

folded

share

Install FreeSql, OceanBase.ManagedDataAccess, and FreeSql.Provider.OceanBase in OceanBase Oracle mode. You can obtain IFreeSql by using OceanBaseProvider<TMark>. For more information about the connection string, see Connection string. For more information about the package and version, see Package reference and usage.

Installation

The installation method is the same as for the basic driver:

dotnet add package FreeSql
dotnet add package OceanBase.ManagedDataAccess
dotnet add package FreeSql.Provider.OceanBase

Connection string

Use the Oracle mode format supported by the driver. Replace the placeholders with the actual values from your environment, and do not directly copy the literals from the example:

server=<host or IP>;port=<port>;user id=<OceanBase Oracle account>;password=<password>;database=<schema name>;

Note

  • user id is the OceanBase Oracle account.
  • database is not recommended to be omitted; the current provider's metadata capabilities will rely on it to identify the current schema.
  • The default port is typically 2881.

Quick start

Replace the connection string with your local configuration (such as a configuration file or environment variable), then create a client and perform a connectivity check:

using FreeSql;
using FreeSql.Provider.OceanBase;

var connectionString = "<your connection string>";

using var fsql = new OceanBaseProvider<object>(
    connectionString,
    null);

fsql.Aop.CurdBefore += (_, e) => Console.WriteLine(e.Sql);

var ok = fsql.Ado.ExecuteConnectTest();
Console.WriteLine($"ConnectTest={ok}");

In a single-database scenario, it is recommended to use IFreeSql as a singleton.

Full example

Creating tables, performing CRUD operations, pagination, and other tasks are similar to standard FreeSql usage. Replace <your connection string> with your actual connection string.

using System;
using FreeSql;
using FreeSql.DataAnnotations;
using FreeSql.Provider.OceanBase;

var connectionString =
    "<your connection string>";

using var fsql = new OceanBaseProvider<object>(connectionString, null);

fsql.Aop.CurdBefore += (_, e) => Console.WriteLine(e.Sql);
fsql.Aop.CurdAfter += (_, e) => Console.WriteLine($"Rows={e.AffectedRows}");

fsql.CodeFirst.SyncStructure<DemoUser>();

var userId = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

fsql.Insert(new DemoUser
{
    Id = userId,
    Name = "Alice",
    Age = 28,
    CreatedAt = DateTime.Now,
    LastLoginAt = DateTimeOffset.Now
}).ExecuteAffrows();

var user = fsql.Select<DemoUser>()
    .Where(x => x.Id == userId)
    .First();

Console.WriteLine($"{user.Id} {user.Name} {user.Age}");

fsql.Update<DemoUser>()
    .Set(x => x.Name, "Alice-Updated")
    .Set(x => x.Age, 29)
    .Where(x => x.Id == userId)
    .ExecuteAffrows();

var page = fsql.Select<DemoUser>()
    .OrderBy(x => x.Id)
    .Page(1, 10)
    .ToList();

Console.WriteLine($"PageCount={page.Count}");

fsql.Delete<DemoUser>()
    .Where(x => x.Id == userId)
    .ExecuteAffrows();

[Table(Name = "T_DEMO_USER")]
public class DemoUser
{
    [Column(Name = "ID", IsPrimary = true)]
    public long Id { get; set; }

    [Column(Name = "NAME", StringLength = 100)]
    public string Name { get; set; } = string.Empty;

    [Column(Name = "AGE")]
    public int? Age { get; set; }

    [Column(Name = "CREATED_AT")]
    public DateTime CreatedAt { get; set; }

    [Column(Name = "LAST_LOGIN_AT")]
    public DateTimeOffset? LastLoginAt { get; set; }
}

Read/write separation example

The OceanBaseProvider<TMark> constructor supports primary and read-only connection strings:

using var fsql = new OceanBaseProvider<object>(
    masterConnectionString,
    new[] { slaveConnectionString1, slaveConnectionString2 });

This is suitable for businesses that already have read/write separation scenarios.

Native SQL example

It is recommended to use parameterized queries. If you need to execute native SQL, you can use the Ado API:

var count = fsql.Ado.ExecuteScalar<int>(
    "select count(1) from T_DEMO_USER where AGE >= :minAge",
    new OceanBase.OracleParameter(":minAge", 18));

CodeFirst / DbFirst

The current adapter layer supports basic CodeFirst and DbFirst capabilities.

CodeFirst

Example of synchronizing table structure based on entities:

fsql.CodeFirst.SyncStructure<DemoUser>();

Default type mapping examples (actual versions may vary):

CLR Type OceanBase Oracle Type
bool number(1)
int number(11)
long number(21)
decimal number(10,2)
string varchar2(255)
DateTime timestamp(6)
DateTimeOffset timestamp(6) with local time zone
byte[] blob
Guid char(36 char)

If your business has specific requirements for length, precision, or column types, it is recommended to explicitly configure column attributes on the entity rather than relying solely on default mappings.

DbFirst

var exists = fsql.DbFirst.ExistsTable("<table name>");
var table = fsql.DbFirst.GetTableByName("<table name>");
var tables = fsql.DbFirst.GetTablesByDatabase("<database or schema name consistent with the connection string>");

This is suitable for simple metadata reading, inspections, or code generation.

Recommended Integration Approach

We recommend organizing your business project as follows:

  1. Create an IFreeSql instance once when the application starts.
  2. Reuse it as a singleton through dependency injection (DI).
  3. Continue using the original FreeSql features and CRUD writing methods.
  4. Explicitly specify key metadata such as table names, column names, length, and precision.

This approach typically requires only replacing the driver and provider initialization code, with minimal changes to the business layer's CRUD operations.

Considerations

  • Do not omit the database parameter in the connection string. The current provider's metadata capabilities rely on database to identify the current schema.
  • If some APIs that return entities after updates/deletes are unavailable, consider using affected rows APIs or querying before modifying/deleting.
  • For complex scenarios involving cross-schema operations or schema-qualified table names, plan accordingly based on your business needs rather than relying solely on automatic table creation.
  • Keep native SQL parameterized.

Minimum Connectivity Verification

using FreeSql.Provider.OceanBase;

var fsql = new OceanBaseProvider<object>("<your connection string>", null);
Console.WriteLine(fsql.Ado.ExecuteConnectTest());

A return value of True indicates successful connectivity.

Previous topic

Use SqlSugar
Last

Next topic

Overview of commonly used interfaces
Next
What is on this page
Installation
Connection string
Quick start
Full example
Read/write separation example
Native SQL example
CodeFirst / DbFirst
CodeFirst
DbFirst
Recommended Integration Approach
Considerations
Minimum Connectivity Verification