Введение Entity Framework Core


public string? Name { get; set; }


Download 0.7 Mb.
bet2/7
Sana16.06.2023
Hajmi0.7 Mb.
#1514490
1   2   3   4   5   6   7
Bog'liq
11-Ma`ruza

public string? Name { get; set; }

public int Age { get; set; }

public int CompanyId { get; set; }

public Company? Company { get; set; }

}

public class ApplicationContext : DbContext

{

public DbSet Users { get; set; } = null!;

public DbSet Companies { get; set; } = null!;

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

{

optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=helloappdb;

Trusted_Connection=True;");

}}

1. Saqlangan funksiyalar

Muntazam SQL so'rovlari bilan bir qatorda, Entity Framework Core ham ma'lumotlar bazasida yaratilgan saqlangan funktsiyalarni bajarishga imkon beradi.

Misol sifatida MS SQL Server ma'lumotlar bazasidan foydalanib,

C# ilovasida saqlangan funksiyani chaqirishni ko'rib chiqamiz.

Bizning ma'lumotlar bazamiz quyidagi ma'lumotlar konteksti va ob'ektlari bilan tavsiflansin:

using Microsoft.EntityFrameworkCore;

public class Company

{ public int Id { get; set; }

public string? Name { get; set; }

public List Users { get; set; } = new();}

public class User{ public int Id { get; set; }

public string? Name { get; set; }

public int Age { get; set; }

public int CompanyId { get; set; }

public Company? Company { get; set; }}

public class ApplicationContext : DbContext

{

public DbSet Users { get; set; } = null!;


Download 0.7 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling