⚠️ Preview Release: RoomSharp is currently in Preview. Learn more →

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

View on NuGet →

Database Providers

SQL Server

Bash
dotnet add package RoomSharp.SqlServer

View on NuGet →

PostgreSQL

Bash
dotnet add package RoomSharp.PostgreSql

View on NuGet →

MySQL / MariaDB

Bash
dotnet add package RoomSharp.MySql

View on NuGet →

Dependency Injection (Optional)

Bash
dotnet add package RoomSharp.DependencyInjection

View on NuGet →

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.cs
  • UserDaoImpl.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:

  1. Clean and rebuild: dotnet clean && dotnet build
  2. Restart your IDE
  3. Check that you're targeting .NET 8.0 or later
  4. Ensure RoomSharp package is properly installed

Compilation Errors

Common issues:

  • Missing required keyword on non-nullable reference properties
  • Incorrect attribute usage (check documentation)
  • Database class not marked as abstract

Next Steps