Skip to content

Latest commit

 

History

History
205 lines (142 loc) · 5.5 KB

File metadata and controls

205 lines (142 loc) · 5.5 KB

SQLite Setup Guide for Dividex

This guide explains how to set up SQLite for the Dividex budgeting application.

Prerequisites

1. .NET 10.0 SDK with MAUI Workload

You need the .NET 10.0 SDK installed with the MAUI workload. If you haven't already:

On macOS:

# Install .NET 10.0 SDK (if not already installed)
# Download from: https://dotnet.microsoft.com/download/dotnet/10.0

# Install MAUI workload
dotnet workload install maui

On Windows:

# Install .NET 10.0 SDK (if not already installed)
# Download from: https://dotnet.microsoft.com/download/dotnet/10.0

# Install MAUI workload
dotnet workload install maui

2. Platform-Specific Requirements

For macOS (Mac Catalyst):

  • macOS 12.0 or later
  • Xcode 15.0 or later (for Mac Catalyst development)
  • Command Line Tools for Xcode

For iOS:

  • macOS 12.0 or later
  • Xcode 15.0 or later
  • iOS 15.0 or later device/simulator

For Android:

  • Android SDK (installed via Visual Studio or Android Studio)
  • Android API 24 or later

For Windows:

  • Windows 10 version 17763.0 or later
  • Visual Studio 2022 with .NET MAUI workload

SQLite Installation

Good news: You don't need to install SQLite separately!

SQLite is automatically included when you install the NuGet packages. The Entity Framework Core SQLite provider handles everything for you.

Setup Steps

Step 1: Restore NuGet Packages

After cloning or downloading the project, restore the NuGet packages:

cd /path/to/dividex
dotnet restore

This will download:

  • Microsoft.EntityFrameworkCore.Sqlite (version 10.0.0)
  • Microsoft.EntityFrameworkCore.Tools (version 10.0.0)

Step 2: Build the Project

Build the project to ensure everything compiles correctly:

dotnet build

Step 3: Run the Application

The database will be automatically created on first run. Run the application:

For Mac Catalyst:

dotnet run -f net10.0-maccatalyst

For iOS Simulator:

dotnet run -f net10.0-ios

For Android:

dotnet run -f net10.0-android

For Windows:

dotnet run -f net10.0-windows10.0.19041.0

Database Location

The SQLite database file (dividex.db) is automatically created in the application's local data folder:

  • macOS (Mac Catalyst): ~/Library/Application Support/com.companyname.dividex/dividex.db
  • iOS: App's Documents directory (sandboxed)
  • Android: App's data directory (sandboxed)
  • Windows: %LOCALAPPDATA%\dividex\dividex.db

You typically don't need to access this file directly, but it's useful to know where it's stored for backup purposes.

How It Works

  1. First Run: When you first launch the app, the database is automatically created using EnsureCreated(). This happens in MauiProgram.cs during app startup.

  2. Data Persistence: All budget data (salary, categories, subcategories, fixed costs, variable costs) is stored in the SQLite database.

  3. No Manual Setup Required: The database schema is defined in Data/BudgetDbContext.cs and is automatically applied on first run.

Troubleshooting

Issue: "Could not load file or assembly 'SQLite'"

Solution: Make sure you've restored NuGet packages:

dotnet restore

Issue: "Database file cannot be created"

Solution: Check that the application has write permissions to the local application data folder. This is usually automatic, but on some systems you may need to grant permissions.

Issue: "Entity Framework Core tools not found"

Solution: If you need to create migrations (usually not required), install the EF Core tools:

dotnet tool install --global dotnet-ef

Issue: Database not persisting data

Solution:

  1. Check that the database file exists in the location mentioned above
  2. Verify that EnsureCreated() is being called (check MauiProgram.cs)
  3. Ensure you're using the BudgetService or BudgetDbContext correctly in your components

Using SQLite in Your Code

Inject the Service

In your Razor components, inject the BudgetService:

@inject dividex.Services.BudgetService BudgetService

@code {
    protected override async Task OnInitializedAsync()
    {
        var budget = await BudgetService.GetLatestBudgetAsync();
        // Use the budget data...
    }
}

Or Use DbContext Directly

@inject dividex.Data.BudgetDbContext DbContext

@code {
    private async Task LoadData()
    {
        var budgets = await DbContext.Budgets
            .Include(b => b.Categories)
            .ToListAsync();
    }
}

Database Schema

The database contains the following tables:

  • Budgets - Stores budget information (monthly salary, timestamps)
  • Categories - Budget categories (Needs, Wants, Savings, etc.)
  • Subcategories - Subcategories within categories
  • FixedCosts - Fixed cost items (can belong to category or subcategory)
  • VariableCosts - Variable cost items (can belong to category or subcategory)

All relationships are configured with cascade delete, so deleting a budget will remove all associated data.

Additional Resources

Need Help?

If you encounter any issues:

  1. Check that all prerequisites are installed
  2. Run dotnet restore and dotnet build
  3. Verify the database file is being created in the expected location
  4. Check the application logs for error messages