Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions ProjectManager/DataAccess/DataAccess.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="7.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions ProjectManager/DataAccess/Migrations/20231101124242_Initial.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace DataAccess.Migrations
{
/// <inheritdoc />
public partial class Initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Projects",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Projects", x => x.Id);
});

migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
ProjectId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
table.ForeignKey(
name: "FK_Users_Projects_ProjectId",
column: x => x.ProjectId,
principalTable: "Projects",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});

migrationBuilder.CreateIndex(
name: "IX_Users_ProjectId",
table: "Users",
column: "ProjectId");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Users");

migrationBuilder.DropTable(
name: "Projects");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// <auto-generated />
using DataAccess;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

#nullable disable

namespace DataAccess.Migrations
{
[DbContext(typeof(ProjectContext))]
partial class ProjectContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.13")
.HasAnnotation("Relational:MaxIdentifierLength", 128);

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

modelBuilder.Entity("DataAccess.Project", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");

SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));

b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.HasKey("Id");

b.ToTable("Projects");
});

modelBuilder.Entity("DataAccess.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");

SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));

b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<int>("ProjectId")
.HasColumnType("int");

b.HasKey("Id");

b.HasIndex("ProjectId");

b.ToTable("Users");
});

modelBuilder.Entity("DataAccess.User", b =>
{
b.HasOne("DataAccess.Project", "Project")
.WithMany("Users")
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

b.Navigation("Project");
});

modelBuilder.Entity("DataAccess.Project", b =>
{
b.Navigation("Users");
});
#pragma warning restore 612, 618
}
}
}
2 changes: 2 additions & 0 deletions ProjectManager/DataAccess/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
12 changes: 12 additions & 0 deletions ProjectManager/DataAccess/Project.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace DataAccess
{
public class Project
{
public int Id { get; set; }

public string Name { get; set; } = null!;

public List<User> Users { get; set; } = null!;

}
}
31 changes: 31 additions & 0 deletions ProjectManager/DataAccess/ProjectContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

namespace DataAccess
{
public class ProjectContext : DbContext
{
public ProjectContext() {
}

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

public DbSet<User> Users { get; set; } = null!;

public DbSet<Project> Projects { get; set; } = null!;

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(@"Server=.\SQLEXPRESS;Database=ProjectManagerDb;Trusted_Connection=True; Encrypt=False");
}


}
}
11 changes: 11 additions & 0 deletions ProjectManager/DataAccess/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace DataAccess;

public class User
{
public int Id { get; set; }

public string Name { get; set; } = null!;

public Project Project { get; set; } = null!;

}
25 changes: 25 additions & 0 deletions ProjectManager/ProjectManager.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34031.279
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataAccess", "DataAccess\DataAccess.csproj", "{F9CACECC-803B-4703-93C4-D0AF78A97756}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F9CACECC-803B-4703-93C4-D0AF78A97756}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F9CACECC-803B-4703-93C4-D0AF78A97756}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F9CACECC-803B-4703-93C4-D0AF78A97756}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F9CACECC-803B-4703-93C4-D0AF78A97756}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {54456466-88A5-45F3-87CA-F9BEF5667958}
EndGlobalSection
EndGlobal