Files
DugunSalonu/Models/dugunsalonuContext.cs

55 lines
1.8 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DugunSalonu.Models
{
public class dugunsalonuContext : DbContext
{
public DbSet<Kullanici> kullanici { get; set; }
public DbSet<Salon> salon { get; set; }
public DbSet<Il> il { get; set; }
public DbSet<Ilce> ilce { get; set; }
public DbSet<Referans> referans { get; set; }
public DbSet<Organizasyon> organizasyon { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Referans>()
.HasIndex(r => new { r.turu, r.kodu })
.IsUnique();
modelBuilder.Entity<Referans>().HasNoKey();
modelBuilder.Entity<Il>().HasMany<Ilce>(i => i.ilceler);
modelBuilder.Entity<Ilce>().HasOne<Il>(i => i.Il);
//fiyat için oluşturulan alanın tipini belirtmek için yapıldı.
modelBuilder.Entity<Organizasyon>(entity =>
{
entity.Property(e => e.fiyat)
.HasColumnType("numeric(18,2)"); // 18 basamak, 2 ondalık
});
/*
// kts alanı için default değer
modelBuilder.Entity<Referans>()
.Property(r => r.kts)
.HasDefaultValueSql("NOW()");*/
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql("Server=edoysoft.com;Database=DugunSalonu;User Id=postgres;Password=MgC1453MgC;", b => b.EnableRetryOnFailure());
base.OnConfiguring(optionsBuilder);
}
}
}