GitHub Copilot ile nesne-ilişkisel eşleme entegrasyonları

GitHub Copilot ve MSSQL uzantısı, SQL Server ve Azure SQL Veritabanı için tüm önemli nesne-ilişkisel eşleme (ORM) çerçeveleriyle çalışır. Bu referans, desteklenen ORM'leri, her birinin neler yapabileceğini ve sizi bir SQL Server tablosundan tipli model, göç ve veri erişim yöntemine götüren uçtan uca bir örneği kapsar.

Önemli çıkarımlar

  • GitHub Copilot, seçtiğiniz ORM'ye özel modeller, göçler ve veri erişim kodları oluşturur.
  • Sohbet katılımcısı@mssql veritabanı şemanızı okur ve ORM kodu oluştururken bunu bağlam olarak kullanır.
  • Özel komutlar, hem Transact-SQL (T-SQL) hem de ORM katmanlarında konvansiyonları uygulayabilir.

ORM destek matrisi

ORM Stack Models Migrations Şema öncesi Kod öncelikli
Entity Framework Core .NET / C# Yes Yes Yes Yes
Prisma Node.js / TypeScript Yes Yes Yes Yes
Devam Etmek Node.js Yes Yes Yes Yes
SQLAlchemy Python Yes Evet (Alembic aracılığıyla) Yes Yes
Django ORM Python Yes Yes Yes Limited
TypeORM Node.js / TypeScript Yes Yes Yes Yes
Çiseleme Node.js / TypeScript Yes Yes Yes Yes
Dapper .NET / C# Micro-ORM Manual Hayır Yes

Uçtan uca senaryo

Her bölüm aynı senaryoyu kullanır: SQL Server'da SalesLT.Customer bir email sütun eklemek, tipli bir model oluşturmak ve veri erişim yöntemi oluşturmak istersiniz.

Entity Framework Core (Varlık Çerçevesi Çekirdeği)

1. Modeli oluşturun

@mssql Generate an Entity Framework Core entity class for
SalesLT.Customer. Use C# records where appropriate. Target
Entity Framework Core 9 with SQL Server provider.

2. Göçü oluşturun

@mssql Generate an Entity Framework Core migration to add an
`Email` column (nvarchar(256), nullable) to the Customer entity.
Use the EF Core Add-Migration conventions and include both the
Up and Down methods.

3. Veri erişim yöntemini oluşturun

@mssql Write a CustomerRepository method that returns all active
customers ordered by LastName. Use the DbContext pattern, async/await,
and return IReadOnlyList<Customer>.

Prisma

1. Şema modelini oluşturun

@mssql Generate a Prisma model for SalesLT.Customer using the
sqlserver provider. Use @map annotations to match the existing
column names. Set the primary key and unique constraints explicitly.

2. Göçü oluşturun

@mssql Generate a Prisma migration SQL file to add an `email`
column (NVARCHAR(256), nullable) to the SalesLT.Customer table,
compatible with the sqlserver provider.

3. Veri erişim yöntemini oluşturun

@mssql Write a TypeScript function that uses the Prisma client to
return all active customers ordered by last name, including strict
TypeScript types.

Devam Etmek

1. Modeli oluşturun

@mssql Generate a Sequelize model class for SalesLT.Customer using
the sequelize-typescript decorators pattern. Include data type
mappings for DATETIME2 and NVARCHAR columns.

2. Göçü oluşturun

@mssql Generate a Sequelize migration in JavaScript to add an
`email` column (STRING(256), nullable) to the `Customer` table in
the `SalesLT` schema.

3. Veri erişim yöntemini oluşturun

@mssql Write a Sequelize repository method using async/await that
returns all active customers ordered by LastName. Use model scopes
for the `active` filter.

SQLAlchemy

1. Modeli oluşturun

@mssql Generate a SQLAlchemy 2.0 model for SalesLT.Customer using
the declarative Mapped[] syntax. Use the pyodbc driver connection
string format for SQL Server.

2. Alembik göçü üretin

@mssql Generate an Alembic migration script to add an `email`
column (NVARCHAR(256), nullable) to the SalesLT.Customer table.
Include both upgrade and downgrade functions.

3. Veri erişim yöntemini oluşturun

@mssql Write a SQLAlchemy 2.0 async repository method using
select() and scalars() that returns all active customers ordered
by last name.

Django ORM

1. Modeli oluşturun

@mssql Generate a Django model for SalesLT.Customer using
django-mssql-backend. Include Meta.db_table to map to the
existing table name with the SalesLT schema.

2. Göçü oluşturun

@mssql Generate a Django migration to add an `email` field
(CharField, max_length=256, null=True) to the Customer model.
Use the AddField operation.

3. Veri erişim yöntemini oluşturun

@mssql Write a Django queryset manager method that returns all
active customers ordered by last_name, using select_related for
any foreign key fields.

TypeORM

1. Varlığı oluşturun

@mssql Generate a TypeORM entity class for SalesLT.Customer.
Use decorators for @Entity, @Column, @PrimaryGeneratedColumn.
Include DATETIME2 and NVARCHAR mappings for SQL Server.

2. Göçü oluşturun

@mssql Generate a TypeORM migration class to add an `email`
column (nvarchar 256, nullable) to the SalesLT.Customer table.
Include both up and down methods.

3. Veri erişim yöntemini oluşturun

@mssql Write a TypeORM repository method that uses the query
builder to return all active customers ordered by last name.
Include strict TypeScript types.

Çiseleme

1. Şemayı üretin

@mssql Generate a Drizzle schema definition for SalesLT.Customer
using the mssql dialect. Include type-safe column mappings for
nvarchar, datetime2, and bit types.

2. Göçü oluşturun

@mssql Generate a Drizzle migration SQL file to add an `email`
column (nvarchar 256, nullable) to the SalesLT.Customer table.

3. Veri erişim yöntemini oluşturun

@mssql Write a Drizzle query using the query builder that returns
all active customers ordered by last name. Use type-safe column
references.

Dapper

Dapper, şema oluşturma veya göç desteği olmayan bir mikro-ORM'dir, ancak GitHub Copilot, mevcut bir şemaya karşı Dapper'ın uzantı yöntemlerini kullanan veri erişim yöntemleri oluşturabilir.

@mssql Write a Dapper-based repository method in C# that returns
all active customers ordered by LastName. Use parameterized
queries and a typed Customer record.

Yaygın kalıplar ve uyarılar

  • Entity Framework Core + SQL Server derleme. Küçük harf hassasiyetli karşılaştırmalar için, açıkça sorgularda ayarlanır EF.Functions.Collate . Varsayılan derlemenin SQL Server'ın sunucu seviyesi ayarıyla eşleştiğini varsaymayın.
  • Prisma + MSSQL bağlantı dizesi alıntı. Azure SQL Veritabanı bağlantı dizileri şifrelerdeki özel karakterlerin dikkatli URL kodlaması gerektirir. Prisma SQL Server sağlayıcı dokümantlarına bakınız.
  • SQLAlchemy + pyodbc driver. Doğru sürücü sürümünü kur ve referans ver (ODBC Driver 18 for SQL Server 2026 itibarıyla). Sürprizlerden kaçınmak için versiyonları sabitleyin requirements.txt .
  • Django ORM + birincil anahtar eşleme. IDENTITYsütunlar, veri yükleri için paket ve IDENTITY_INSERT işleme gerektirirdjango-mssql-backend.
  • TypeORM + camelCase. Takımınız belirli bir konvansiyon kullanıyorsa, özel talimatlarınızla uyumlu adlandırma stratejilerini belirleyin entityPrefix ve kullanın.

Deneyiminizi paylaşma

MSSQL uzantısı için GitHub Copilot'ı geliştirmemize ve geliştirmemize yardımcı olmak için aşağıdaki GitHub sorun şablonunu kullanarak geri bildiriminizi gönderin: GitHub Copilot Geri Bildirimi

Geri bildirim gönderirken şunları dahil etmeyi göz önünde bulundurun:

  • Test edilen senaryolar: Şema oluşturma, sorgu oluşturma, güvenlik, yerelleştirme gibi odaklandığınız alanları bize bildirin.

  • İyi çalışan şeyler: Sorunsuz, yararlı veya beklentilerinizi aşan deneyimleri açıklayın.

  • Sorunlar veya hatalar: Tüm sorunları, tutarsızlıkları veya kafa karıştırıcı davranışları dahil edin. Ekran görüntüleri veya ekran kayıtları özellikle yararlıdır.

  • İyileştirme önerileri: Kullanılabilirliği geliştirmeye, kapsamı genişletmeye veya GitHub Copilot'un yanıtlarını geliştirmeye yönelik fikirleri paylaşın.