NewLife.XCode - Data Middleware / Super ORM
🌐 简体中文 | 繁體中文 | Español | Deutsch | 日本語 | Français | Português | Русский | 한국어 | العربية
NewLife.XCode is a high-performance .NET data middleware focused on "CRUD + extreme performance + massive data". It includes multi-level caching, automatic modeling/migration, sharding, strongly-typed queries and cross-database migration. It supports MySQL / SQLite / SqlServer / Oracle / PostgreSQL / TDengine / InfluxDB / OpenTSDB / IoTDB / Prometheus / DaMeng / KingBase / HighGo / DB2 / ClickHouse / DuckDB / MongoDB / Hana (SAP HANA) / IRIS (InterSystems) / VastBase / Network virtual database / NovaDb / SonnetDB / Presto / Trino / Firebird / Snowflake / Vertica / SAP ASE / Teradata / YashanDB / MonetDB / Google Cloud Spanner and more; MySQL and PostgreSQL protocol-compatible engines (TiDB / Doris / StarRocks / openGauss / Redshift and others) reuse those providers. Production deployments reach tens of billions of rows per table, and query throughput can reach billions of QPS (with caching strategies).
Docs: https://newlifex.com/xcode Community QQ groups: 1600800 / 1600838
Contents: Quick Start · Why XCode · Main Features · Ecosystem Map · Documentation · Contributing · Team · License
Supported Databases
XCode reaches every database through a separate ADO.NET driver package. Install the package that matches your database; when a driver is missing, the error message also names the package to add. 33 communication-protocol providers are built in — relational, embedded, time-series, columnar, document, federated and cloud data warehouses — covering 55 databases in total: 33 dedicated providers plus 22 protocol-compatible databases that reuse the MySQL, PostgreSQL or Prometheus provider.
| Database |
Provider |
NuGet driver package |
Type |
| SQL Server |
SqlServer |
System.Data.SqlClient |
Relational |
| MySQL / MariaDB |
MySql |
NewLife.MySql |
Relational |
| PostgreSQL |
PostgreSQL |
Npgsql |
Relational |
| Oracle |
Oracle |
Oracle.ManagedDataAccess.Core |
Relational |
| SQLite |
SQLite |
Microsoft.Data.Sqlite |
Embedded |
| Firebird |
Firebird |
FirebirdSql.Data.FirebirdClient |
Relational |
| DB2 |
DB2 |
IBM.Data.DB2.Core |
Relational |
| SAP ASE (Sybase) |
Ase |
AdoNetCore.AseClient |
Relational |
| DaMeng |
DaMeng |
dmdbms.DmProvider |
Relational |
| Kingbase |
KingBase |
Kdbndp |
Relational |
| HighGo |
HighGo |
Nhgdb |
Relational |
| VastBase |
VastBase |
Npgsql |
Relational |
| YashanDB |
YashanDB |
Yashandb.Data.YashandbClient |
Relational |
| Hana |
Hana |
Sap.Data.Hana |
In-memory |
| IRIS |
IRIS |
InterSystems.Data.IRISClient |
Multi-model |
| ClickHouse |
ClickHouse |
ClickHouse.Client |
Columnar |
| Vertica |
Vertica |
Vertica.Data |
Columnar |
| MonetDB |
MonetDB |
MonetDb.Mapi |
Columnar |
| DuckDB |
DuckDB |
DuckDB.NET.Data |
Embedded OLAP |
| Snowflake |
Snowflake |
Snowflake.Data |
Cloud DW |
| Teradata |
Teradata |
Teradata.Client.Provider |
Cloud DW |
| Google Cloud Spanner |
Spanner |
Google.Cloud.Spanner.Data |
Cloud |
| TDengine |
TDengine |
NewLife.TDengine |
Time-series |
| InfluxDB |
InfluxDB |
Built-in |
Time-series |
| OpenTSDB |
OpenTSDB |
Built-in |
Time-series |
| IoTDB |
IoTDB |
Built-in |
Time-series |
| Prometheus |
Prometheus |
Built-in |
Time-series |
| MongoDB |
MongoDB |
MongoDB.Driver |
Document |
| Presto |
Presto |
NewLife.Presto |
Federated |
| Trino |
Trino |
Trino.Data.ADO |
Federated |
| NovaDb |
NovaDb |
NewLife.NovaDb |
Embedded / network |
| SonnetDB |
SonnetDB |
SonnetDB |
Embedded / remote |
| Network |
Network |
Built-in |
Virtual |
Protocol-compatible databases need no new provider; the provider name in the connection string selects the built-in alias:
| Database |
Reused provider |
Connection provider alias |
| MariaDB |
MySql |
mariadb |
| TiDB |
MySql |
tidb |
| StarRocks |
MySql |
starrocks |
| Apache Doris |
MySql |
doris |
| OceanBase (MySQL mode) |
MySql |
oceanbase |
| SingleStore |
MySql |
singlestore |
| PolarDB |
MySql |
polardb |
| TDSQL |
MySql |
tdsql |
| GoldenDB |
MySql |
goldendb |
| GreatDB |
MySql |
greatdb |
| Databend |
MySql |
databend |
| openGauss |
PostgreSQL |
opengauss |
| GaussDB |
PostgreSQL |
gaussdb |
| Greenplum |
PostgreSQL |
greenplum |
| Amazon Redshift |
PostgreSQL |
redshift |
| CockroachDB |
PostgreSQL |
cockroach |
| YugabyteDB |
PostgreSQL |
yugabyte |
| TimescaleDB |
PostgreSQL |
timescale |
| QuestDB |
PostgreSQL |
questdb |
| GreptimeDB |
PostgreSQL |
greptimedb |
| CrateDB |
PostgreSQL |
cratedb |
| VictoriaMetrics |
Prometheus |
victoriametrics |
The same catalog is available at runtime through DatabaseProducts.All; DatabaseProducts.ProtocolCount and DatabaseProducts.Count return the two totals. The Access and SqlCe providers are retained but disabled.
Quick Start
Install
NuGet reference (any project):
dotnet add package NewLife.XCode
Or use the template scaffold:
dotnet new install NewLife.Templates
dotnet new xcode --name Demo.Data
cd Demo.Data
dotnet build
The strong-name certificate is built in (newlife.snk); you can recompile for a private enterprise framework.
Define the model (db.xml)
<?xml version="1.0" encoding="utf-8"?>
<Tables Version="1.0" Output="MyEntity" NameSpace="Model" BaseClass="Entity" ConnName="DB">
<Table Name="UserInfo" Description="User information">
<Columns>
<Column Name="Id" DataType="Int32" Identity="True" PrimaryKey="True" Description="Member id" />
<Column Name="UserName" DataType="String" Nullable="False" Description="Member name" />
<Column Name="Password" DataType="String" Nullable="False" Description="Member password" />
<Column Name="Age" DataType="Int32" Description="Member age" />
</Columns>
</Table>
</Tables>
Generate entity classes
- Download xcodetool.exe into the directory and double-click it, or run:
dotnet tool install xcodetool -g --prerelease → xcode db.xml.
- Generates: 用户信息.cs (data class, overwritten) + 用户信息.Biz.cs (business class, not overwritten).
CRUD
using XCode;
var user = new UserInfo { UserName = "Zhang San", Password = "123456", Age = 18 };
user.Insert();
Console.WriteLine("Inserted a new record, user id: " + user.Id);
var u2 = UserInfo.FindById(user.Id);
u2.Age = 19;
u2.Update();
var list = UserInfo.FindAll(UserInfo._.Age > 10 & UserInfo._.UserName == "Zhang San");
UserInfo.FindById(user.Id)?.Delete();
When using caches: fewer than 1000 entities → full-table cache; otherwise use regular queries / single-object cache.
Why XCode
- Homegrown and original: fully developed in China with no third-party components, self-controlled and backed by long-term maintenance.
- Simplicity: 90% of business scenarios need only single-table entity operations, with no hand-written SQL.
- Dapper compatible: executes arbitrary SQL queries and maps them to any entity model; fully compatible with Dapper usage while adding caching, read/write splitting and tracing.
- Extreme performance: multi-level caching on the core path + batch optimization + in-memory joins; query speed can be far higher than raw SQL.
- Massive data: native paging and sharding strategies; production projects reach tens of billions of rows per table; paging algorithms adapt to multiple databases.
- Stable and mature: 20+ years of evolution and broad production validation; keeps compatibility with older .NET Framework versions (from net45).
- Automatic migration: model/entity is the schema; new fields are synchronized automatically on deployment, with no extra SQL scripts.
- Distributed evolution: native table-level / time / primary-key sharding strategies for smooth splitting and scaling.
- Pluggable: DAL abstraction + separated providers; custom database adapters are supported.
Main Features
Modeling & Code Generation (5)
| Feature |
Key Characteristics |
| XML model (Tables/Columns/Indexes) |
The model is the single source of truth; attributes cover indexes, unique constraints, default values, descriptions and extended properties. |
| Code generator |
xcodetool (global tool / exe) or the VS T4 template turns the XML model into entity classes. |
Data class (.cs) |
Overwritten on every generation; holds fields and basic queries. |
Business class (.Biz.cs) |
Not overwritten after the first generation; place custom logic here. |
| Auto-generated methods |
Indexes and columns produce FindByXxx / Search helper methods and templates automatically. |
Entity Runtime & DAL (7)
| Component |
Responsibility |
IEntity / Entity |
Rich domain model encapsulating fields, validation and lifecycle. |
IEntityOperate |
Static operation entry point (Find / FindAll / Query, etc.). |
EntityFactory |
Entity metadata cache factory. |
EntitySession (Meta.Session) |
Context of an entity on a specific connection/table, with session-level cache/statistics. |
Meta |
Entity static context (table schema, fields, caches, sharding policy, etc.). |
DAL / IDatabase / IDbSession |
Unified database access and metadata operations. |
CheckTables() |
Checks and synchronizes the schema on startup/first access, asynchronously or synchronously as needed. |
Query DSL (8)
| Capability |
Key Characteristics |