31 lines
1.0 KiB
C#
31 lines
1.0 KiB
C#
using System;
|
|
using System.Linq;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace SampleApplication
|
|
{
|
|
public class SampleDbContext : DbContext
|
|
{
|
|
public SampleDbContext(DbContextOptions<SampleDbContext> options) : base(options)
|
|
{
|
|
}
|
|
|
|
public DbSet<Entities.ShapeInput> Shapes { get; set; }
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
modelBuilder.Entity<Entities.ShapeInput>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id);
|
|
entity.Property(e => e.Id).ValueGeneratedOnAdd();
|
|
entity.Property(e => e.Type).IsRequired();
|
|
entity.Property(e => e.Dimensions).IsRequired();
|
|
entity.Property(e => e.Dimensions).HasConversion(
|
|
v => string.Join(',', v),
|
|
v => v.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(double.Parse).ToArray());
|
|
});
|
|
}
|
|
}
|
|
}
|