Skip to content

SQL #13

@seydaoztrk

Description

@seydaoztrk

//
using System;
using EFCodeFirst.ORM.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

#nullable disable

namespace EFCodeFirst.Migrations
{
// Bu sınıf, EF Core tarafından oluşturulmuş bir migration'dır.
// NorthwindLibraryContext bağlamına (DbContext) aittir.
[DbContext(typeof(NorthwindLibraryContext))]
[Migration("20240312084857_ProductTableCreated")]
partial class ProductTableCreated
{
///


/// Bu metot, veritabanı şemasının nasıl oluşturulacağını tanımlar.
/// Entity Framework, bu metodu migration sırasında kullanır.
///

protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618

        // EF Core'un versiyon bilgisini ve SQL Server için tanımlayıcı uzunluğunu ayarlar.
        modelBuilder
            .HasAnnotation("ProductVersion", "8.0.2")
            .HasAnnotation("Relational:MaxIdentifierLength", 128);

        // SQL Server'da Identity (otomatik artan) kolonları kullanmak için yapılandırma.
        SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

        // Product entity'si için tablo yapılandırması başlıyor.
        modelBuilder.Entity("EFCodeFirst.ORM.Models.Product", b =>
        {
            // Primary Key olan ProductID kolonu tanımlanıyor.
            b.Property<int>("ProductID")
                .ValueGeneratedOnAdd()           // Otomatik artan (Identity)
                .HasColumnType("int");

            SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ProductID"));

            // CategoryID kolonunun tanımı (nullable int)
            b.Property<int?>("CategoryID")
                .HasColumnType("int");

            // Ürün aktif mi değil mi onu gösteren boolean değer
            b.Property<bool>("Discontinued")
                .HasColumnType("bit");

            // Ürün adı (zorunlu, max 40 karakter)
            b.Property<string>("ProductName")
                .IsRequired()
                .HasMaxLength(40)
                .HasColumnType("nvarchar(40)");

            // Ambalaj bilgisi (opsiyonel, max 20 karakter)
            b.Property<string>("QuantityPerUnit")
                .HasMaxLength(20)
                .HasColumnType("nvarchar(20)");

            // Yeniden sipariş seviyesi (opsiyonel)
            b.Property<short?>("ReorderLevel")
                .HasColumnType("smallint");

            // Tedarikçi ID (opsiyonel)
            b.Property<int?>("SupplierID")
                .HasColumnType("int");

            // Ürün fiyatı (opsiyonel, para birimi)
            b.Property<decimal?>("UnitPrice")
                .HasColumnType("money");

            // Stoktaki ürün adedi (opsiyonel)
            b.Property<short?>("UnitsInStock")
                .HasColumnType("smallint");

            // Siparişteki ürün adedi (opsiyonel)
            b.Property<short?>("UnitsOnOrder")
                .HasColumnType("smallint");

            // Primary Key tanımı
            b.HasKey("ProductID");

            // Tablo adı: "products"
            b.ToTable("products");

            // --- İLİŞKİLER (Foreign Key) ---
            // Eğer Category ve Supplier tabloları tanımlıysa, ilişkiler böyle eklenebilir:
            /*
            b.HasOne("EFCodeFirst.ORM.Models.Category", null)
                .WithMany()
                .HasForeignKey("CategoryID")
                .OnDelete(DeleteBehavior.Restrict);

            b.HasOne("EFCodeFirst.ORM.Models.Supplier", null)
                .WithMany()
                .HasForeignKey("SupplierID")
                .OnDelete(DeleteBehavior.Restrict);
            */
        });

#pragma warning restore 612, 618
}
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions