ZerkyXII
ZerkyXII
Explore posts from servers
CC#
Created by ZerkyXII on 7/3/2024 in #help
Multiple 1 to Many Relationships in Entity Framework
So it just works now, idk I didn't do anything. Redid the migration a few times after testing a few things and it just works..
36 replies
CC#
Created by ZerkyXII on 7/3/2024 in #help
Multiple 1 to Many Relationships in Entity Framework
so that from the Phases works totally fine. It's not until I add the tasks to the repo. Trying out the breakpoint to see if it can give me the deats though
36 replies
CC#
Created by ZerkyXII on 7/3/2024 in #help
Multiple 1 to Many Relationships in Entity Framework
public async Task<Phases> CreateAsync(Phases phasesModel)
{
await _context.Phases.AddAsync(phasesModel);
await _context.SaveChangesAsync();
return phasesModel;
}
public async Task<Phases> CreateAsync(Phases phasesModel)
{
await _context.Phases.AddAsync(phasesModel);
await _context.SaveChangesAsync();
return phasesModel;
}
36 replies
CC#
Created by ZerkyXII on 7/3/2024 in #help
Multiple 1 to Many Relationships in Entity Framework
public async Task<Tasks> CreateAsync(Tasks tasksModel)
{
await _context.Tasks.AddAsync(tasksModel);
await _context.SaveChangesAsync();
return tasksModel;
}
public async Task<Tasks> CreateAsync(Tasks tasksModel)
{
await _context.Tasks.AddAsync(tasksModel);
await _context.SaveChangesAsync();
return tasksModel;
}
36 replies
CC#
Created by ZerkyXII on 7/3/2024 in #help
Multiple 1 to Many Relationships in Entity Framework
that's the full error
36 replies
CC#
Created by ZerkyXII on 7/3/2024 in #help
Multiple 1 to Many Relationships in Entity Framework
36 replies
CC#
Created by ZerkyXII on 7/3/2024 in #help
Multiple 1 to Many Relationships in Entity Framework
Ik it's super confusing but maybe should I just share a git link cause I got repository/interfaces/dto/mappers/controllers that all connect. I'm thinking i'm beefing something up
36 replies
CC#
Created by ZerkyXII on 7/3/2024 in #help
Multiple 1 to Many Relationships in Entity Framework
But you're def right haha
36 replies
CC#
Created by ZerkyXII on 7/3/2024 in #help
Multiple 1 to Many Relationships in Entity Framework
Ik I got too deep into it and I'm gonna have to go back and rebuild it so I'm just trying to get the linking down
36 replies
CC#
Created by ZerkyXII on 7/3/2024 in #help
Multiple 1 to Many Relationships in Entity Framework
tasks it like won't auto increment the ID like the phases
36 replies
CC#
Created by ZerkyXII on 7/3/2024 in #help
Multiple 1 to Many Relationships in Entity Framework
Right that's where I'm confused cause the code is the same as phases(just replaced as tasks)
36 replies
CC#
Created by ZerkyXII on 7/3/2024 in #help
Multiple 1 to Many Relationships in Entity Framework
[Table("Tasks")]
public class Tasks
{
public int TasksID { get; set; }
public string TasksName { get; set; } = String.Empty;
public string TasksDescription { get; set; } = String.Empty;
public string TasksStatus { get; set; } = String.Empty;
public string TasksStartDate { get; set; } = String.Empty;
public string TasksEndDate { get; set; } = String.Empty;

public int? ProjectsID { get; set; }
public Projects? Projects { get; set; }
}
[Table("Tasks")]
public class Tasks
{
public int TasksID { get; set; }
public string TasksName { get; set; } = String.Empty;
public string TasksDescription { get; set; } = String.Empty;
public string TasksStatus { get; set; } = String.Empty;
public string TasksStartDate { get; set; } = String.Empty;
public string TasksEndDate { get; set; } = String.Empty;

public int? ProjectsID { get; set; }
public Projects? Projects { get; set; }
}
36 replies
CC#
Created by ZerkyXII on 7/3/2024 in #help
Multiple 1 to Many Relationships in Entity Framework
[Table("Phases")]
public class Phases
{
public int PhasesID { get; set; }
public string PhasesName { get; set; } = String.Empty;
public string PhasesDescription { get; set; } = String.Empty;
public string PhasesStartDate { get; set; } = String.Empty;
public string PhasesEndDate { get; set; } = String.Empty;
// Project Link
public int? ProjectsID { get; set; }
public Projects? Projects { get; set; }
}
[Table("Phases")]
public class Phases
{
public int PhasesID { get; set; }
public string PhasesName { get; set; } = String.Empty;
public string PhasesDescription { get; set; } = String.Empty;
public string PhasesStartDate { get; set; } = String.Empty;
public string PhasesEndDate { get; set; } = String.Empty;
// Project Link
public int? ProjectsID { get; set; }
public Projects? Projects { get; set; }
}
36 replies
CC#
Created by ZerkyXII on 7/3/2024 in #help
Multiple 1 to Many Relationships in Entity Framework
[Table("Projects")]
public class Projects
{
// Project SQL Table Properties
public int ProjectsID { get; set; }
public string ProjectsName { get; set; } = String.Empty;
public string ProjectsShortcode { get; set; } = String.Empty;
public string ProjectsDescription { get; set; } = String.Empty;
// Phases Link
public List<Phases> Phases { get; set; } = new List<Phases>();
// Tasks Link
public List<Tasks> Tasks { get; set; } = new List<Tasks>();
}
[Table("Projects")]
public class Projects
{
// Project SQL Table Properties
public int ProjectsID { get; set; }
public string ProjectsName { get; set; } = String.Empty;
public string ProjectsShortcode { get; set; } = String.Empty;
public string ProjectsDescription { get; set; } = String.Empty;
// Phases Link
public List<Phases> Phases { get; set; } = new List<Phases>();
// Tasks Link
public List<Tasks> Tasks { get; set; } = new List<Tasks>();
}
36 replies
CC#
Created by ZerkyXII on 7/3/2024 in #help
Multiple 1 to Many Relationships in Entity Framework
So I have Phases, that is working all good. So I pretty much copied the exact thing for Tasks. But even with adding onModelBuilder it's still pissed hahaha
36 replies
CC#
Created by ZerkyXII on 7/3/2024 in #help
Multiple 1 to Many Relationships in Entity Framework
AppDBContext :
public class AppDBContext : DbContext
{
public AppDBContext(DbContextOptions options) : base(options)
{

}
public DbSet<Projects> Projects { get; set; }
public DbSet<Phases> Phases { get; set; }
public DbSet<Tasks> Tasks { get; set; }
public class AppDBContext : DbContext
{
public AppDBContext(DbContextOptions options) : base(options)
{

}
public DbSet<Projects> Projects { get; set; }
public DbSet<Phases> Phases { get; set; }
public DbSet<Tasks> Tasks { get; set; }
36 replies
CC#
Created by ZerkyXII on 7/3/2024 in #help
Multiple 1 to Many Relationships in Entity Framework
Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details.
---> Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot insert the value NULL into column 'TasksID', table 'rnpm.dbo.Tasks'; column does not allow nulls. INSERT fails.
Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details.
---> Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot insert the value NULL into column 'TasksID', table 'rnpm.dbo.Tasks'; column does not allow nulls. INSERT fails.
36 replies
CC#
Created by ZerkyXII on 7/3/2024 in #help
Multiple 1 to Many Relationships in Entity Framework
Yeah I tried that but it just isn't happy. I'll get you an error code one sec
36 replies