Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b2484e18a5 |
@@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj",
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BussinessLogick", "BussinessLogick\BussinessLogick.csproj", "{D098214E-146D-4B68-9EF7-89F5DB610CB7}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BussinessLogick", "BussinessLogick\BussinessLogick.csproj", "{D098214E-146D-4B68-9EF7-89F5DB610CB7}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataBase", "DataBase\DataBase.csproj", "{608AC528-CB79-4E4E-BFF6-7EF154A56F6C}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -27,6 +29,10 @@ Global
|
|||||||
{D098214E-146D-4B68-9EF7-89F5DB610CB7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{D098214E-146D-4B68-9EF7-89F5DB610CB7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{D098214E-146D-4B68-9EF7-89F5DB610CB7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{D098214E-146D-4B68-9EF7-89F5DB610CB7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{D098214E-146D-4B68-9EF7-89F5DB610CB7}.Release|Any CPU.Build.0 = Release|Any CPU
|
{D098214E-146D-4B68-9EF7-89F5DB610CB7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{608AC528-CB79-4E4E-BFF6-7EF154A56F6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{608AC528-CB79-4E4E-BFF6-7EF154A56F6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{608AC528-CB79-4E4E-BFF6-7EF154A56F6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{608AC528-CB79-4E4E-BFF6-7EF154A56F6C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@@ -6,4 +6,11 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.5">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
12
ClassLibrary1/IConfigurationDatabase.cs
Normal file
12
ClassLibrary1/IConfigurationDatabase.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ClassLibrary1;
|
||||||
|
|
||||||
|
public interface IConfigurationDatabase
|
||||||
|
{
|
||||||
|
string ConnectionString { get; }
|
||||||
|
}
|
||||||
14
ClassLibrary1/Program.cs
Normal file
14
ClassLibrary1/Program.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ClassLibrary1;
|
||||||
|
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
21
DataBase/Article.cs
Normal file
21
DataBase/Article.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DataBase;
|
||||||
|
|
||||||
|
internal class Article
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
public required string Id { get; set; }
|
||||||
|
public required string Title { get; set; }
|
||||||
|
public required string Tema { get; set; }
|
||||||
|
public DateTime DateCreat { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey("ArticleId")]
|
||||||
|
public List<Author>? Authors { get; set; }
|
||||||
|
}
|
||||||
23
DataBase/Author.cs
Normal file
23
DataBase/Author.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DataBase;
|
||||||
|
|
||||||
|
internal class Author
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
public required string Id { get; set; }
|
||||||
|
public required string FIO { get; set; }
|
||||||
|
public required string Email { get; set; }
|
||||||
|
public DateTime BirthDate { get; set; }
|
||||||
|
public required string Work { get; set; }
|
||||||
|
public required string ArticleId { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey("ArticleId")]
|
||||||
|
public Article? Article { get; set; }
|
||||||
|
}
|
||||||
27
DataBase/DataBase.csproj
Normal file
27
DataBase/DataBase.csproj
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.5" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.5">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.5" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.5">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\ClassLibrary1\ClassLibrary1.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
13
DataBase/DefaultConfigurationDatabase.cs
Normal file
13
DataBase/DefaultConfigurationDatabase.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using ClassLibrary1;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DataBase;
|
||||||
|
|
||||||
|
class DefaultConfigurationDatabase : IConfigurationDatabase
|
||||||
|
{
|
||||||
|
public string ConnectionString => "";
|
||||||
|
}
|
||||||
45
DataBase/LibraryDbContext.cs
Normal file
45
DataBase/LibraryDbContext.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using ClassLibrary1;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection.Emit;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DataBase;
|
||||||
|
|
||||||
|
internal class LibraryDbContext : DbContext
|
||||||
|
{
|
||||||
|
private readonly IConfigurationDatabase? _configurationDatabase;
|
||||||
|
|
||||||
|
public LibraryDbContext(IConfigurationDatabase configurationDatabase)
|
||||||
|
{
|
||||||
|
_configurationDatabase = configurationDatabase;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
optionsBuilder.UseNpgsql(_configurationDatabase?.ConnectionString, o => o.SetPostgresVersion(12, 2));
|
||||||
|
base.OnConfiguring(optionsBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity<Author>().HasIndex(x => x.Email).IsUnique();
|
||||||
|
|
||||||
|
modelBuilder.Entity<Author>()
|
||||||
|
.HasOne(a => a.Article)
|
||||||
|
.WithMany(a => a.Authors)
|
||||||
|
.HasForeignKey(a => a.ArticleId)
|
||||||
|
.OnDelete(DeleteBehavior.Restrict);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DbSet<Article> Articles { get; set; }
|
||||||
|
public DbSet<Author> Authors { get; set; }
|
||||||
|
}
|
||||||
17
DataBase/SampleContextFactory.cs
Normal file
17
DataBase/SampleContextFactory.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Design;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DataBase;
|
||||||
|
|
||||||
|
internal class SampleContextFactory : IDesignTimeDbContextFactory<LibraryDbContext>
|
||||||
|
{
|
||||||
|
public LibraryDbContext CreateDbContext(string[] args)
|
||||||
|
{
|
||||||
|
return new LibraryDbContext(new DefaultConfigurationDatabase());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user