This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.EntityFrameworkCore; | |
using Dapper; | |
using System.Collections.Generic; | |
using System.Data; | |
using System.Threading.Tasks; | |
// Определение сущностей | |
public class User | |
{ | |
public int Id { get; set; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Модель User | |
using System.ComponentModel.DataAnnotations; | |
public class User | |
{ | |
public int Id { get; set; } | |
[Required] | |
[StringLength(50, MinimumLength = 3)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.ComponentModel.DataAnnotations; | |
public class User | |
{ | |
[Key] | |
public int Id { get; set; } | |
[Required] | |
public string Username { get; set; } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Самый популярный товар (продавался больше всего раз) | |
SELECT TOP 1 ProductID, Name, COUNT(*) AS SalesCount | |
FROM Sale | |
GROUP BY ProductID, Name | |
ORDER BY SalesCount DESC; | |
2. Процентное соотношение проданных товаров каждой категории | |
SELECT c.CategoryName, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 линия |
NewerOlder