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
19 changes: 19 additions & 0 deletions DataAccess/DataAccess.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<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.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>
37 changes: 37 additions & 0 deletions DataAccess/EjercicioDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;

namespace DataAccess
{
public class EjercicioDbContext : DbContext
{
public DbSet<Proyecto> Proyectos { get; set; }
public DbSet<Usuario> Usuarios { get; set; }
public DbSet<CargaHoras> CargasDeHoras { get; set; }

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

//protected override void OnModelCreating(ModelBuilder modelBuilder)
//{
// modelBuilder
// .Entity<CargaHoras>()
// .HasOne(e => e.Proyecto)
// .WithMany(e => e.CargasDeHoras)
// .OnDelete(DeleteBehavior.Restrict);

// modelBuilder
// .Entity<Usuario>()
// .HasOne(e => e.Proyecto)
// .WithMany(e => e.Usuarios)
// .OnDelete(DeleteBehavior.Restrict);
//}
}
}
37 changes: 37 additions & 0 deletions DataAccess/Entities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataAccess
{
public class Proyecto
{
public int ProyectoId { get; set; }
public string Nombre { get; set; }
public List<Usuario> Usuarios { get; set; }
}

public class Usuario
{
public int UsuarioId { get; set; }
public string Nombre { get; set; }
public int ProyectoId { get; set; }
public Proyecto Proyecto { get; set; }
public List<CargaHoras> CargasDeHoras { get; set; }
}

public class CargaHoras
{
public int CargaHorasId { get; set; }
public int HorasTrabajadas { get; set; }
public string Descripcion { get; set; }
public int UsuarioId { get; set; }
public Usuario Usuario { get; set; }
public int ProyectoId { get; set; }
public Proyecto Proyecto { get; set; }
}


}
138 changes: 138 additions & 0 deletions DataAccess/Migrations/20231101130338_init.Designer.cs

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

103 changes: 103 additions & 0 deletions DataAccess/Migrations/20231101130338_init.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

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

migrationBuilder.CreateTable(
name: "Usuarios",
columns: table => new
{
UsuarioId = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Nombre = table.Column<string>(type: "nvarchar(max)", nullable: false),
ProyectoId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Usuarios", x => x.UsuarioId);
table.ForeignKey(
name: "FK_Usuarios_Proyectos_ProyectoId",
column: x => x.ProyectoId,
principalTable: "Proyectos",
principalColumn: "ProyectoId",
onDelete: ReferentialAction.Cascade);
});

migrationBuilder.CreateTable(
name: "CargasDeHoras",
columns: table => new
{
CargaHorasId = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
HorasTrabajadas = table.Column<int>(type: "int", nullable: false),
Descripcion = table.Column<string>(type: "nvarchar(max)", nullable: false),
UsuarioId = table.Column<int>(type: "int", nullable: false),
ProyectoId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_CargasDeHoras", x => x.CargaHorasId);
table.ForeignKey(
name: "FK_CargasDeHoras_Proyectos_ProyectoId",
column: x => x.ProyectoId,
principalTable: "Proyectos",
principalColumn: "ProyectoId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_CargasDeHoras_Usuarios_UsuarioId",
column: x => x.UsuarioId,
principalTable: "Usuarios",
principalColumn: "UsuarioId",
onDelete: ReferentialAction.NoAction);
});

migrationBuilder.CreateIndex(
name: "IX_CargasDeHoras_ProyectoId",
table: "CargasDeHoras",
column: "ProyectoId");

migrationBuilder.CreateIndex(
name: "IX_CargasDeHoras_UsuarioId",
table: "CargasDeHoras",
column: "UsuarioId");

migrationBuilder.CreateIndex(
name: "IX_Usuarios_ProyectoId",
table: "Usuarios",
column: "ProyectoId");
}

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

migrationBuilder.DropTable(
name: "Usuarios");

migrationBuilder.DropTable(
name: "Proyectos");
}
}
}
Loading