From d59f55d549385a6200b9113bd6766fbeff9c6e85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=9F=D1=83=D1=82=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=D0=BD?= Date: Wed, 19 Apr 2023 14:32:05 +0400 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D1=82=D1=8F=D0=B3=D0=B8=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=81=D1=83=D1=89=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D1=83=D1=8E=D1=89=D0=B5=D0=B9=20=D0=B1=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- News/News.sln | 25 ++++++++ News/News/Author.cs | 16 +++++ News/News/Category.cs | 22 +++++++ News/News/Comment.cs | 20 ++++++ News/News/News.cs | 26 ++++++++ News/News/News.csproj | 19 ++++++ News/News/NewsContext.cs | 135 +++++++++++++++++++++++++++++++++++++++ News/News/Program.cs | 2 + News/News/User.cs | 16 +++++ 9 files changed, 281 insertions(+) create mode 100644 News/News.sln create mode 100644 News/News/Author.cs create mode 100644 News/News/Category.cs create mode 100644 News/News/Comment.cs create mode 100644 News/News/News.cs create mode 100644 News/News/News.csproj create mode 100644 News/News/NewsContext.cs create mode 100644 News/News/Program.cs create mode 100644 News/News/User.cs diff --git a/News/News.sln b/News/News.sln new file mode 100644 index 0000000..38f2987 --- /dev/null +++ b/News/News.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32901.215 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "News", "News\News.csproj", "{985E9E32-067A-4DB6-8AE5-19A7495E3CC4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {985E9E32-067A-4DB6-8AE5-19A7495E3CC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {985E9E32-067A-4DB6-8AE5-19A7495E3CC4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {985E9E32-067A-4DB6-8AE5-19A7495E3CC4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {985E9E32-067A-4DB6-8AE5-19A7495E3CC4}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C3950A75-07C0-4805-9081-FD72CA18F14C} + EndGlobalSection +EndGlobal diff --git a/News/News/Author.cs b/News/News/Author.cs new file mode 100644 index 0000000..09df7f4 --- /dev/null +++ b/News/News/Author.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; + +namespace News; + +/// +/// авторы +/// +public partial class Author +{ + public int AuthorId { get; set; } + + public string AuthorName { get; set; } = null!; + + public virtual ICollection News { get; set; } = new List(); +} diff --git a/News/News/Category.cs b/News/News/Category.cs new file mode 100644 index 0000000..9d2df68 --- /dev/null +++ b/News/News/Category.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; + +namespace News; + +/// +/// категории +/// +public partial class Category +{ + /// + /// ид категории + /// + public int CategoryId { get; set; } + + /// + /// наименование + /// + public string CategoryName { get; set; } = null!; + + public virtual ICollection News { get; set; } = new List(); +} diff --git a/News/News/Comment.cs b/News/News/Comment.cs new file mode 100644 index 0000000..2564abb --- /dev/null +++ b/News/News/Comment.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; + +namespace News; + +/// +/// комментарии +/// +public partial class Comment +{ + public int UserId { get; set; } + + public int NewsId { get; set; } + + public string CommentText { get; set; } = null!; + + public virtual News News { get; set; } = null!; + + public virtual User User { get; set; } = null!; +} diff --git a/News/News/News.cs b/News/News/News.cs new file mode 100644 index 0000000..85b4ecf --- /dev/null +++ b/News/News/News.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; + +namespace News; + +/// +/// новости +/// +public partial class News +{ + public int NewsId { get; set; } + + public string NewsName { get; set; } = null!; + + public DateOnly? NewsDate { get; set; } + + public int AuthorId { get; set; } + + public int CategoryId { get; set; } + + public virtual Author Author { get; set; } = null!; + + public virtual Category Category { get; set; } = null!; + + public virtual ICollection Comments { get; set; } = new List(); +} diff --git a/News/News/News.csproj b/News/News/News.csproj new file mode 100644 index 0000000..0aba620 --- /dev/null +++ b/News/News/News.csproj @@ -0,0 +1,19 @@ + + + + Exe + net6.0 + enable + enable + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + diff --git a/News/News/NewsContext.cs b/News/News/NewsContext.cs new file mode 100644 index 0000000..d1349c1 --- /dev/null +++ b/News/News/NewsContext.cs @@ -0,0 +1,135 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; + +namespace News; + +public partial class NewsContext : DbContext +{ + public NewsContext() + { + } + + public NewsContext(DbContextOptions options) + : base(options) + { + } + + public virtual DbSet Authors { get; set; } + + public virtual DbSet Categories { get; set; } + + public virtual DbSet Comments { get; set; } + + public virtual DbSet News { get; set; } + + public virtual DbSet Users { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) +#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263. + => optionsBuilder.UseNpgsql("Host=192.168.56.103;Port=5432;Database=news;Username=postgres;Password=54050"); + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.AuthorId).HasName("author_pkey"); + + entity.ToTable("author", tb => tb.HasComment("авторы")); + + entity.Property(e => e.AuthorId) + .HasDefaultValueSql("nextval('author_id_seq'::regclass)") + .HasColumnName("author_id"); + entity.Property(e => e.AuthorName) + .HasMaxLength(150) + .HasColumnName("author_name"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.CategoryId).HasName("category_pkey"); + + entity.ToTable("category", tb => tb.HasComment("категории")); + + entity.Property(e => e.CategoryId) + .HasDefaultValueSql("nextval('category_id_seq'::regclass)") + .HasComment("ид категории") + .HasColumnName("category_id"); + entity.Property(e => e.CategoryName) + .HasMaxLength(150) + .HasComment("наименование") + .HasColumnName("category_name"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.UserId, e.NewsId }).HasName("comment_pkey"); + + entity.ToTable("comment", tb => tb.HasComment("комментарии")); + + entity.Property(e => e.UserId).HasColumnName("user_id"); + entity.Property(e => e.NewsId).HasColumnName("news_id"); + entity.Property(e => e.CommentText) + .HasMaxLength(2000) + .HasColumnName("comment_text"); + + entity.HasOne(d => d.News).WithMany(p => p.Comments) + .HasForeignKey(d => d.NewsId) + .HasConstraintName("news_id"); + + entity.HasOne(d => d.User).WithMany(p => p.Comments) + .HasForeignKey(d => d.UserId) + .HasConstraintName("user_id"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.NewsId).HasName("news_pkey"); + + entity.ToTable("news", tb => tb.HasComment("новости")); + + entity.Property(e => e.NewsId) + .HasDefaultValueSql("nextval('news_id_seq'::regclass)") + .HasColumnName("news_id"); + entity.Property(e => e.AuthorId).HasColumnName("author_id"); + entity.Property(e => e.CategoryId).HasColumnName("category_id"); + entity.Property(e => e.NewsDate).HasColumnName("news_date"); + entity.Property(e => e.NewsName) + .HasMaxLength(200) + .HasColumnName("news_name"); + + entity.HasOne(d => d.Author).WithMany(p => p.News) + .HasForeignKey(d => d.AuthorId) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("author_id"); + + entity.HasOne(d => d.Category).WithMany(p => p.News) + .HasForeignKey(d => d.CategoryId) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("category_id"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.UserId).HasName("user_pkey"); + + entity.ToTable("user", tb => tb.HasComment("пользователи")); + + entity.Property(e => e.UserId) + .HasDefaultValueSql("nextval('user_id_seq'::regclass)") + .HasColumnName("user_id"); + entity.Property(e => e.UserName) + .HasMaxLength(150) + .HasColumnName("user_name"); + }); + modelBuilder.HasSequence("author_id_seq"); + modelBuilder.HasSequence("category_id_seq"); + modelBuilder.HasSequence("comment_id_seq"); + modelBuilder.HasSequence("news_id_seq"); + modelBuilder.HasSequence("user_id_seq"); + + OnModelCreatingPartial(modelBuilder); + } + + partial void OnModelCreatingPartial(ModelBuilder modelBuilder); +} diff --git a/News/News/Program.cs b/News/News/Program.cs new file mode 100644 index 0000000..3751555 --- /dev/null +++ b/News/News/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/News/News/User.cs b/News/News/User.cs new file mode 100644 index 0000000..45e558d --- /dev/null +++ b/News/News/User.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; + +namespace News; + +/// +/// пользователи +/// +public partial class User +{ + public int UserId { get; set; } + + public string UserName { get; set; } = null!; + + public virtual ICollection Comments { get; set; } = new List(); +}