LiteOrm is a lightweight, high-performance .NET ORM framework that combines the speed of micro-ORMs with the functionality of full ORMs. It is suitable for projects that require flexible SQL query handling while prioritizing performance.
Expr.Expr, and ExprStringSqlBuilder extension for custom database capabilities| Option | Usually strongest at |
|---|---|
| EF Core | Migrations, full ecosystem, conventions |
| Dapper | Minimal abstraction and handwritten SQL |
| LiteOrm | Performance, expression extensibility, automatic associations, flexible SQL control |
LiteOrm uses a modular design that clearly separates core functionality, common components, samples, and test code. The project structure is well-organized for easy maintenance and extension.
├── LiteOrm/ # Core library
│ ├── Classes/ # Core classes
│ ├── Converter/ # Converters
│ ├── DAO/ # Data access objects
│ ├── DAOContext/ # Data access context
│ ├── DbAccess/ # Database access
│ ├── Initilizer/ # Initializers
│ ├── Service/ # Service layer
│ └── SqlBuilder/ # SQL builders
├── LiteOrm.Common/ # Common components
│ ├── Attributes/ # Attributes
│ ├── Classes/ # Common classes
│ ├── Converter/ # Common converters
│ ├── Expr/ # Expressions
│ ├── MetaData/ # Metadata
│ ├── Model/ # Models
│ ├── Service/ # Common services
│ ├── SqlBuilder/ # Common SQL builders
│ └── SqlSegment/ # SQL segments
├── LiteOrm.Demo/ # Demo project
│ ├── DAO/ # Demo DAO
│ ├── Data/ # Demo data
│ ├── Demos/ # Demo code
│ ├── Models/ # Demo models
│ └── Services/ # Demo services
├── LiteOrm.Tests/ # Test project
│ ├── Attributes/ # Attribute tests
│ ├── Classes/ # Class tests
│ ├── Converter/ # Converter tests
│ ├── Expr/ # Expression tests
│ ├── Infrastructure/ # Test infrastructure
│ ├── MetaData/ # Metadata tests
│ ├── Models/ # Test models
│ └── Service/ # Service tests
├── LiteOrm.Benchmark/ # Performance benchmark
└── docs/ # Documentation
├── 01-getting-started/ # Getting started guide
├── 02-core-usage/ # Core usage
├── 03-advanced-topics/ # Advanced topics
├── 04-extensibility/ # Extensibility
└── 05-reference/ # Reference
Core Module Responsibilities:
| Module | Main Responsibility | File Location |
|---|---|---|
| DAO | Data access operations | LiteOrm/DAO/ |
| Service | Business services | LiteOrm/Service/ |
| SqlBuilder | SQL statement building | LiteOrm/SqlBuilder/ |
| Expr | Query expressions | LiteOrm.Common/Expr/ |
| Attributes | Entity mapping attributes | LiteOrm.Common/Attributes/ |
| MetaData | Metadata management | LiteOrm.Common/MetaData/ |
LiteOrm uses a layered architecture design that clearly separates data access, business logic, and presentation layers. The system architecture follows the Dependency Inversion Principle, achieving decoupling between layers through interfaces.
graph TD
A[Application Code]
B[Service Layer]
B -->|Uses| C[DAO Layer]
E[DAOContext] -->|Creates| J[DbCommandProxy]
F[Database] -->|Reads| K[AutoLockDataReader]
J -->|Builds| K
K -->|Converts| L[Entity Objects]
A -->|Builds Query| G1[Lambda Expression]
A -->|Builds Query| G2[Expr Expression]
A -->|Builds Query| G3[ExprString]
G1 -->|Converts to| G2
G2 -->|Builds| G3
G2 -->|Passes to| B
G2 -->|Passes to| C
G3 -->|Passes to| C
C -->|Uses| D[SqlBuilder]
D -->|Builds SQL| H[SQL Statement]
H -->|Sets| J
B -->|Transaction Management| I[SessionManager]
I -->|Controls| E
P[DAOContextPool] -->|Provides| E
K -->|Releases| E
Main Process Descriptions:
RegisterLiteOrm() registers services and switches the host to AutofacSearch condition fragment or a full SQL statement[Transaction] attributeThe DAO layer is the core of LiteOrm, providing direct data access operations. It includes multiple implementation classes for different data access scenarios.
Main Components:
Core Features:
The Service layer encapsulates business logic and provides higher-level operation interfaces. It is built on top of the DAO layer, adding transaction management and business rules.
Main Components:
Core Features:
The expression system is a distinctive feature of LiteOrm, providing powerful query building capabilities. It covers three common query entry styles: Lambda expressions, Expr objects, and DAO-only ExprString.
Main Components:
Core Features:
The SQL Builder is responsible for generating optimized SQL statements for different databases based on expressions. It supports multiple database types and provides database-specific syntax and function support.
Main Components:
Core Features:
Metadata management handles the mapping between entity types and database tables. It builds metadata through the attribute system, providing necessary information for DAO and SQL Builder.
Main Components:
Core Features:
LiteOrm provides declarative transaction management through the [Transaction] attribute to mark methods requiring transactions. Transaction management is handled by SessionManager, ensuring multiple operations execute within the same transaction.
Core Features:
Function: Abstract base class for all DAOs, providing common operation methods
Main Methods:
NewCommand(): Create database commandMakeNamedParamCommand(): Create parameterized commandMakeExprCommand(): Create command from expressionGetValue<T>(): Execute query and return single valueExecute(): Execute non-query SQLQuery<TResult>(): Execute query and return result setUse Case: As base class for DAOs, providing common functionality
Function: Handles CRUD operations for entity objects
Main Methods:
Insert(): Insert entityUpdate(): Update entityDelete(): Delete entityDeleteByKeys(): Delete by primary keysSearch(): Query entitiesBatchInsert(): Batch insertBatchUpdate(): Batch updateBatchDelete(): Batch deleteUse Case: Directly operate entity objects, execute CRUD operations
Function: Database command proxy, encapsulates DbCommand, provides parameter processing and execution functionality, combined with AutoLockDataReader to implement transactions and async lock management.
Main Methods:
CreateParameter(): Create database parameterExecuteNonQuery(): Execute non-query commandExecuteReader(): Execute query and return data readerExecuteScalar(): Execute query and return single valueUse Case: Encapsulate database commands, handle parameter and execution operations
Function: Auto-locking data reader, ensures thread safety during data reading
Main Methods:
Read(): Read next recordGetValue(): Get column valueGetInt32()/GetString()/etc.: Get specific type valuesDispose(): Release resourcesUse Case: Safely read database query results
Function: Provides complete business operations for entities
Main Methods:
Insert(): Insert entityUpdate(): Update entityDelete(): Delete entityBatchInsert(): Batch insertBatchUpdate(): Batch updateBatchDelete(): Batch deleteSearch(): Query entitiesSearchOne(): Query single entitySearchAsync(): Async queryUse Case: Use in business logic layer, providing complete entity operations
Function: Service focused on query operations
Main Methods:
Search(): Query entitiesSearchOne(): Query single entitySearchAsync(): Async queryCount(): Count recordsUse Case: Scenarios requiring only query functionality
Function: Base expression class, provides query building capability
Main Methods:
Prop(): Create property expressionExists<T>(): Create existence subqueryFrom<T>(): Create query starting from tableToPreparedSql(): Convert to parameterized SQL statementUse Case: Build complex query conditions
Function: Logical expression, used to build WHERE conditions
Main Operators:
&: AND operation|: OR operation!: NOT operationUse Case: Build complex logical conditions
Function: Base SQL builder class, provides SQL generation functionality
Main Methods:
ToSqlName(): Convert to SQL nameToSqlParam(): Convert to SQL parameterConvertToDbValue(): Convert to database valueConvertFromDbValue(): Convert from database valueBuildSelectSql(): Build SELECT statementBuildFunctionSql(): Build function SQL statementUse Case: Generate database-specific SQL statements
Function: Represents metadata of a database table
Main Properties:
Name: Table nameColumns: Column collectionKeys: Primary key columnsDefinition: Table definitionUse Case: Provide table metadata information
Function: Provider of table information
Main Methods:
GetTable(): Get table informationGetColumn(): Get column informationUse Case: Build and manage table metadata
| Technology/Dependency | Version | Purpose |
|---|---|---|
| .NET | 8.0+ | Runtime environment |
| .NET Standard | 2.0+ | Cross-platform support |
| Autofac.Extensions.DependencyInjection | 10.0.0 | Autofac container integration used by RegisterLiteOrm() |
| Autofac.Extras.DynamicProxy | 7.1.0 | Autofac interception support |
| Microsoft.Extensions.DependencyInjection | 10.0.0 | DI abstractions and ServiceCollection ecosystem |
| Castle.Core | 5.2.1 | Dynamic proxy core |
| Castle.Core.AsyncInterceptor | 2.1.0 | Async interceptor |
| Microsoft.Extensions.Hosting.Abstractions | 10.0.5 | Hosting abstractions |
| Microsoft.Extensions.Logging.Abstractions | 10.0.5 | Logging abstractions |
| System.Text.Json | 10.0.5 | JSON processing |
Database Support: