Installation
Get RoomSharp up and running in your .NET project
NuGet Packages
RoomSharp is distributed as a set of NuGet packages. Choose the packages based on your database provider:
Core Package (includes SQLite)
Bash
dotnet add package RoomSharp
Database Providers
SQL Server
Bash
dotnet add package RoomSharp.SqlServer
PostgreSQL
Bash
dotnet add package RoomSharp.PostgreSql
MySQL / MariaDB
Bash
dotnet add package RoomSharp.MySql
Dependency Injection (Optional)
Bash
dotnet add package RoomSharp.DependencyInjection
Framework Requirements
RoomSharp targets modern .NET versions:
- .NET 8.0 (LTS)
- .NET 9.0
- .NET 10.0 (Preview)
📝 Note: Make sure your project targets one of these frameworks. RoomSharp uses
the latest C# language features and Roslyn source generators.
Quick Start
After installing the packages, create your first RoomSharp database:
C#
using RoomSharp.Attributes;
using RoomSharp.Core;
// 1. Define an entity
[Entity(TableName = "users")]
public class User
{
[PrimaryKey(AutoGenerate = true)]
public long Id { get; set; }
public required string Name { get; set; }
}
// 2. Define a DAO
[Dao]
public interface IUserDao
{
[Insert]
long Insert(User user);
[Query("SELECT * FROM users")]
Task<List<User>> GetAllAsync();
}
// 3. Define your database
[Database(Version = 1, Entities = [typeof(User)])]
public abstract class AppDatabase(IDatabaseProvider provider)
: RoomDatabase(provider)
{
public abstract IUserDao UserDao { get; }
}
// 4. Build and use
var db = RoomDatabase.Builder<AppDatabaseImpl>()
.UseSqlite("myapp.db")
.Build();
db.UserDao.Insert(new User { Name = "Alice" });
var users = await db.UserDao.GetAllAsync();
Using with Dependency Injection
If you're building an ASP.NET Core application, use the DI package:
C# - Program.cs
using RoomSharp.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
// Register RoomSharp database
builder.Services.AddRoomSharpDatabase<AppDatabase>(context =>
{
var connString = builder.Configuration.GetConnectionString("Default")!;
context.UseSqlite(connString);
context.Builder
.SetVersion(1)
.SetEntities(typeof(User));
});
// Register DAOs
builder.Services.AddRoomSharpDao<AppDatabase, IUserDao>(db => db.UserDao);
var app = builder.Build();
app.Run();
Verify Installation
Build your project to trigger the source generator:
Bash
dotnet build
You should see the generated files in your IDE. Look for:
AppDatabaseImpl.g.csUserDaoImpl.g.cs
✅ Success! If you see the generated files and your project builds without errors,
RoomSharp is ready to use.
Troubleshooting
Source Generator Not Running
If generated files don't appear:
- Clean and rebuild:
dotnet clean && dotnet build - Restart your IDE
- Check that you're targeting .NET 8.0 or later
- Ensure RoomSharp package is properly installed
Compilation Errors
Common issues:
- Missing
requiredkeyword on non-nullable reference properties - Incorrect attribute usage (check documentation)
- Database class not marked as
abstract
Next Steps
- Learn about Entities - Define your data models
- Learn about DAOs - Create data access objects
- Database Providers - Configure different databases