DOCUMENTATION

V 1.0.3

DB conf

DB conf — раздел, отвечающий за конфигурацию базы данных: подключение, параметры окружения и общие настройки

application.json

{
    "ConnectionStrings": {
        "Default": "Server=(localdb)\\MSSQLLocalDb;Database=WepAppDb; Trusted_Connection=True;"
    },
    "Logging": {
        "LogLevel": {
            "Default": "Information",
            "Microsoft.AspNetCore": "Warning"
        }
    },
    "AllowedHosts": "*"
}

Program.cs

builder.WebHost.UseUrls("http://*:7010");

builder.Services.AddDbContext<AppDbContext>(options =>
    options.UseSqlServer(builder.Configuration.GetConnectionString("Default")));

Data/AppDbContext.cs

using Microsoft.EntityFrameworkCore;
using WebApplication2.Models;

namespace WebApplication2.Data
{
    public class AppDbContext : DbContext
    {
        public DbSet<Product> Products => Set<Product>();
        public DbSet<User> Users => Set<User>();

        public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
    }
}

Models/Products.cs

namespace WebApplication2.Models
{
    public class Product
    {
        public int Id { get; set; }
        public string Name { get; set; } = "";
        public int Price { get; set; }
    }

    public class User
    {
        public int Id { get; set; }
        public string Name { get; set; } = "";
        public string Useranme { get; set; } = "";
        public string password { get; set; } = "";
        public string? Image { get; set; }
    }
}