47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
public class ChattingContext : DbContext
|
|
{
|
|
public DbSet<ChatMessage> Messages { get; set; }
|
|
|
|
public string DbPath { get; }
|
|
|
|
public ChattingContext()
|
|
{
|
|
DbPath = "chat.db";
|
|
}
|
|
|
|
// 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}");
|
|
}
|
|
|
|
public class Room
|
|
{
|
|
[Key]
|
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
|
public string? Id { get; set; }
|
|
|
|
public string? RoomJoinCode { get; set; }
|
|
|
|
// koble tilsammen ChatMessage til Room
|
|
// https://www.entityframeworktutorial.net/efcore/one-to-many-conventions-entity-framework-core.aspx
|
|
public ChatMessage? ChatMessage { get; set; }
|
|
|
|
}
|
|
|
|
public class ChatMessage
|
|
{
|
|
[Key]
|
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
|
public string? Id { get; set; }
|
|
|
|
public string? User { get; set; }
|
|
public string? Message { get; set; }
|
|
} |