32 lines
956 B
C#
32 lines
956 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 DbSet<Greenhouse> Greenhouses { 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");
|
|
}
|
|
}
|
|
}
|