using Microsoft.Data.Entity; using




Download 0,79 Mb.
bet4/5
Sana25.01.2024
Hajmi0,79 Mb.
#145486
1   2   3   4   5
Bog'liq
Mavzu Web dasturlash Reja
AXXBK 6-MI, O\'simliklarning kelib chiqishi ikkilamchi bo\'lgan moddalar, К.и такриз-мукова 2023, AHMAD YASSAVIYNING “DEVONI HIKMAT” ASARI VA UNING XUSUSIYATLARI, yangi 7 labaratoriya, rL6VnYwAEMo3I5sagPzdV60M2ImpEV0A7iHTjrds, Mustaqillik yillarida davlat boshqaruvi tizimida amalga oshirilg, 8574155кен123, Majburiy fanlar test, 123, 2Вpdf, a.b.c. darajalar, Bazarbaev Quwanishbek oz betinshetexnosferik korsetkishler (1), Urganch davlat universiteti «yengil sanoat texnologiyalari va ji
using Microsoft.Data.Entity;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Linq;
namespace ContosoBooks.Models {
public static class SampleData {
public static void Initialize(IServiceProvider serviceProvider) {
var context = serviceProvider.GetService();
context.Database.Migrate();
if (!context.Book.Any()) {
var austen = context.Author.Add(
new Author { LastName = "Austen", FirstMidName = "Jane" }).Entity;
var dickens = context.Author.Add(
new Author { LastName = "Dickens", FirstMidName = "Charles" }).Entity;
var cervantes = context.Author.Add(
new Author { LastName = "Cervantes", FirstMidName = "Miguel" }).Entity;
context.Book.AddRange(
new Book() {
Title = "Pride and Prejudice",
Year = 1813,
Author = austen,
Price = 9.99M,
Genre = "Comedy of manners"
},
new Book() {
Title = "Northanger Abbey",
Year = 1817,
Author = austen,
Price = 12.95M,
Genre = "Gothic parody"
},
new Book() {
Title = "David Copperfield",
Year = 1850,
Author = dickens,
Price = 15,
Genre = "Bildungsroman"
},
new Book() {
Title = "Don Quixote",
Year = 1617,
Author = cervantes,
Price = 8.95M,
Genre = "Picaresque"
}
);
context.SaveChanges();
}
}
}
}

Siz ushbu ma'lumot sinfini ishlab chiqarish kodiga kiritmaysiz, ammo u bizning stsenariyimiz uchun ishlaydi.


Keyingi, Solution Explorer-da, Startup.cs faylini oching. Configure usuliga quyidagi satrlarni qo'shing:
SampleData.Initialize(app.ApplicationServices);
Shundan so'ng, to'liq Startup.cs fayli quyidagicha bo'ladi:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Data.Entity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using ContosoBooks.Models;
using ContosoBooks.Services;
namespace ContosoBooks
{
public class Startup
{
public Startup(IHostingEnvironment env)
{
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
if (env.IsDevelopment())
{
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
builder.AddUserSecrets();
}
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; set; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity()
.AddEntityFrameworkStores()
.AddDefaultTokenProviders();

Download 0,79 Mb.
1   2   3   4   5




Download 0,79 Mb.

Bosh sahifa
Aloqalar

    Bosh sahifa



using Microsoft.Data.Entity; using

Download 0,79 Mb.