31 lines
892 B
C#
31 lines
892 B
C#
using Cloud.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Cloud;
|
|
public class ApplicationContext : DbContext
|
|
{
|
|
public DbSet<User> Users { get; set; } = null!;
|
|
public DbSet<Farm> Farms { get; set; } = null!;
|
|
|
|
public ApplicationContext(DbContextOptions<ApplicationContext> options)
|
|
: base(options)
|
|
{
|
|
}
|
|
|
|
public ApplicationContext()
|
|
: base(new DbContextOptionsBuilder<ApplicationContext>()
|
|
.UseNpgsql("Host=localhost;Port=5438;Database=main_database;Username=postgres;Password=12345")
|
|
.Options)
|
|
{
|
|
Database.EnsureCreated();
|
|
}
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
if (!optionsBuilder.IsConfigured)
|
|
{
|
|
optionsBuilder.UseNpgsql("Host=localhost;Port=5438;Database=main_database;Username=postgres;Password=12345");
|
|
}
|
|
}
|
|
}
|