2017-05-30 15:01:58 +02:00
|
|
|
|
namespace Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure
|
|
|
|
|
{
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
2017-06-01 20:16:19 +02:00
|
|
|
|
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Repositories;
|
2017-05-30 15:01:58 +02:00
|
|
|
|
using Microsoft.eShopOnContainers.Services.Locations.API.Model;
|
2017-06-01 20:16:19 +02:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-05-30 15:01:58 +02:00
|
|
|
|
|
2017-06-01 20:16:19 +02:00
|
|
|
|
public class LocationsContext : DbContext, IUnitOfWork
|
2017-05-30 15:01:58 +02:00
|
|
|
|
{
|
|
|
|
|
public LocationsContext(DbContextOptions options) : base(options)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DbSet<Locations> Locations { get; set; }
|
2017-06-01 20:16:19 +02:00
|
|
|
|
public DbSet<FrontierPoints> FrontierPoints { get; set; }
|
|
|
|
|
public DbSet<UserLocation> UserLocation { get; set; }
|
2017-05-30 15:01:58 +02:00
|
|
|
|
|
|
|
|
|
protected override void OnModelCreating(ModelBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
builder.Entity<Locations>(ConfigureLocations);
|
|
|
|
|
builder.Entity<FrontierPoints>(ConfigureFrontierPoints);
|
2017-06-01 20:16:19 +02:00
|
|
|
|
builder.Entity<UserLocation>(ConfigureUserLocation);
|
2017-05-30 15:01:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConfigureLocations(EntityTypeBuilder<Locations> builder)
|
|
|
|
|
{
|
|
|
|
|
builder.ToTable("Locations");
|
|
|
|
|
|
|
|
|
|
builder.HasKey(cl => cl.Id);
|
|
|
|
|
|
|
|
|
|
builder.Property(cl => cl.Id)
|
2017-06-01 20:16:19 +02:00
|
|
|
|
.ForSqlServerUseSequenceHiLo("locations_seq")
|
2017-05-30 15:01:58 +02:00
|
|
|
|
.IsRequired();
|
|
|
|
|
|
|
|
|
|
builder.Property(cb => cb.Code)
|
|
|
|
|
.IsRequired()
|
|
|
|
|
.HasColumnName("LocationCode")
|
|
|
|
|
.HasMaxLength(15);
|
|
|
|
|
|
|
|
|
|
builder.HasMany(f => f.Polygon)
|
|
|
|
|
.WithOne(l => l.Location)
|
|
|
|
|
.IsRequired();
|
|
|
|
|
|
|
|
|
|
builder.Property(cb => cb.Description)
|
|
|
|
|
.HasMaxLength(100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConfigureFrontierPoints(EntityTypeBuilder<FrontierPoints> builder)
|
|
|
|
|
{
|
|
|
|
|
builder.ToTable("FrontierPoints");
|
|
|
|
|
|
|
|
|
|
builder.HasKey(fp => fp.Id);
|
|
|
|
|
|
|
|
|
|
builder.Property(fp => fp.Id)
|
2017-06-01 20:16:19 +02:00
|
|
|
|
.ForSqlServerUseSequenceHiLo("frontier_seq")
|
2017-05-30 15:01:58 +02:00
|
|
|
|
.IsRequired();
|
2017-06-01 20:16:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConfigureUserLocation(EntityTypeBuilder<UserLocation> builder)
|
|
|
|
|
{
|
|
|
|
|
builder.ToTable("UserLocation");
|
|
|
|
|
|
|
|
|
|
builder.Property(ul => ul.Id)
|
|
|
|
|
.ForSqlServerUseSequenceHiLo("UserLocation_seq")
|
|
|
|
|
.IsRequired();
|
|
|
|
|
|
|
|
|
|
builder.HasIndex(ul => ul.UserId).IsUnique();
|
2017-05-30 15:01:58 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|