LiveChat/Model.cs

33 lines
928 B
C#
Raw Normal View History

2023-03-27 13:30:27 +00:00
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 ChatMessage
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public string? Id { get; set; }
public string? User { get; set; }
public string? Message { get; set; }
}