Skip to content

Instantly share code, notes, and snippets.

using Microsoft.EntityFrameworkCore;
using Dapper;
using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;
// Определение сущностей
public class User
{
public int Id { get; set; }
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
// Определение моделей
public class User
{
public int Id { get; set; }
1. Модель User
using System.ComponentModel.DataAnnotations;
public class User
{
public int Id { get; set; }
[Required]
[StringLength(50, MinimumLength = 3)]
1. Базовый интерфейс репозитория
public interface IRepository<T> where T : class
{
void Add(T entity);
IEnumerable<T> GetAll();
T GetById(int id);
void Update(T entity);
void Delete(int id);
}
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
namespace MyDatabaseProject
{
public class User
{
public int Id { get; set; }
public string Username { get; set; } = string.Empty;
using System.ComponentModel.DataAnnotations;
public class User
{
[Key]
public int Id { get; set; }
[Required]
public string Username { get; set; }
1. Самый популярный товар (продавался больше всего раз)
SELECT TOP 1 ProductID, Name, COUNT(*) AS SalesCount
FROM Sale
GROUP BY ProductID, Name
ORDER BY SalesCount DESC;
2. Процентное соотношение проданных товаров каждой категории
SELECT c.CategoryName,
1.
public void GetDatabasesInfo()
{
string query = @"
SELECT name AS DatabaseName,
SUM(size * 8 * 1024) AS SizeInBytes
FROM sys.master_files
WHERE type = 0
GROUP BY name";
CREATE PROCEDURE GetProducerProductCount
AS
BEGIN
SELECT pr.name AS ProducerName, COUNT(p.id) AS ProductCount
FROM Producer pr LEFT JOIN Product p ON pr.id = p.id_producer
GROUP BY pr.name
END
CREATE PROCEDURE GetTopSellingProduct
AS
SELECT AVG(Value) AS среднее_арифм
FROM (VALUES (10), (20), (30), (40)) AS Numbers(Value)
SELECT X, Y, X * Y AS результат
FROM (VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10)) AS X(x),
(VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10)) AS Y(y)
SELECT LEFT(NEWID(), 10) AS рандом_пароль
SELECT REPLICATE('*', 10) AS линия