API updates for functional code
This commit is contained in:
31
house-plant-api/Context/AppDbContext.cs
Normal file
31
house-plant-api/Context/AppDbContext.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
namespace house_plant_api.Context
|
||||
{
|
||||
using house_plant_api.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
public class AppDbContext : DbContext
|
||||
{
|
||||
public DbSet<Device> Devices { get; set; }
|
||||
|
||||
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.Entity<Device>()
|
||||
.HasKey(d => d.Id);
|
||||
|
||||
modelBuilder.Entity<Device>()
|
||||
.Property(d => d.Name)
|
||||
.IsRequired();
|
||||
|
||||
modelBuilder.Entity<Device>()
|
||||
.Property(d => d.Nickname);
|
||||
|
||||
modelBuilder.Entity<Device>()
|
||||
.Property(d => d.Uuid)
|
||||
.IsRequired();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user