RoomSharp generates type-safe data access code at build time, keeping your C# models and SQL aligned while staying multi-provider friendly.
Compile-time code generation eliminates runtime reflection. No IL weaving, just pure compiled C# for maximum performance.
Common abstractions over SQLite, SQL Server, PostgreSQL, and MySQL. Switch providers with a single builder method call.
2-5X faster than baseline with zero allocations in hot loops. Prepared statement reuse for maximum throughput.
Built-in transaction helpers with automatic rollback on exceptions. Use [Transaction] attribute for clean, type-safe code.
Custom type mapping with ITypeConverter. Store complex types as JSON, serialize enums, or transform data however you need.
Combine handwritten migrations with auto-migration metadata. Fallback to destructive mode for development databases.
[Entity(TableName = "users")]
[Index(Value = ["Email"], Unique = true)]
public class User
{
[PrimaryKey(AutoGenerate = true)]
public long Id { get; set; }
[Unique]
public required string Email { get; set; }
public string? Name { get; set; }
}
[Dao]
public interface IUserDao
{
[Insert]
long Insert(User user);
[Query("SELECT * FROM users WHERE Email = :email")]
Task<User?> FindByEmailAsync(string email);
[Transaction]
async Task<long> UpsertAsync(User user)
{
var existing = await FindByEmailAsync(user.Email);
if (existing is null)
return Insert(user);
existing.Name = user.Name;
Update(existing);
return existing.Id;
}
}
[Database(Version = 1, Entities = [typeof(User)])]
public abstract class AppDatabase(
IDatabaseProvider provider,
ILogger? logger = null)
: RoomDatabase(provider, logger)
{
public abstract IUserDao UserDao { get; }
}
var db = RoomDatabase.Builder<AppDatabaseImpl>()
.UseSqlite("app.db")
.SetJournalMode(JournalMode.WAL)
.EnableMultiInstanceInvalidation()
.SetAutoCloseTimeout(TimeSpan.FromMinutes(5))
.Build();
var userId = db.UserDao.Insert(
new User { Email = "john@acme.dev", Name = "John" }
);
var user = await db.UserDao.FindByEmailAsync("john@acme.dev");
| Feature | RoomSharp | Dapper | Entity Framework Core |
|---|---|---|---|
| Compile-Time Code Generation | ✓ | ✗ | ✗ |
| Zero Runtime Reflection | ✓ | ✗ | ✗ |
| IL-Based Mapping | ✓ | ✗ | ✗ |
| High-Performance Batch Insert | ✓ | ✓ | Partial |
| Type-Safe Queries | ✓ | ✗ | ✓ |
| Multi-Database Support | ✓ | ✓ | ✓ |
| Migration System | ✓ | ✗ | ✓ |
| Low Memory Allocations | ✓ | ✓ | ✗ |
Choose the provider package for your database:
# Core package (includes SQLite)
dotnet add package RoomSharp
# SQL Server
dotnet add package RoomSharp.SqlServer
# PostgreSQL
dotnet add package RoomSharp.PostgreSql
# MySQL/MariaDB
dotnet add package RoomSharp.MySql
# Dependency Injection (Optional)
dotnet add package RoomSharp.DependencyInjection