Lectureplan/UWLib/LectureContext.cs
Robin Weichselbraun 824df98750 Add project files.
2024-10-12 14:04:23 +02:00

42 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace UWLib
{
public class LectureContext : DbContext
{
public DbSet<Lecture> Lectures { get; set; }
public DbSet<LectureEvent> LectureEvents { get; set; }
public string DbPath { get; }
public LectureContext(string path)
{
DbPath = path;
this.Database.Migrate();
}
public LectureContext()
{
var folder = Environment.SpecialFolder.LocalApplicationData;
var path = Environment.GetFolderPath(folder);
DbPath = System.IO.Path.Join(path, "lecture.db");
DbPath = "lecture.db";
this.Database.Migrate();
}
// The following configures EF to create a Sqlite database file in the
// special "local" folder for your platform.
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite($"Data Source={DbPath}");
}
}