fix table connection
This commit is contained in:
parent
00660345fc
commit
d5e5fe9a3f
@ -10,10 +10,11 @@ using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MySqlConnector;
|
||||
|
||||
namespace PSTW_CentralSystem.Areas.MMS.Controllers
|
||||
{
|
||||
public class SimpleTarballDto
|
||||
public class TarballPdfDto
|
||||
{
|
||||
// From tbl_marine_tarball
|
||||
public int Id { get; set; }
|
||||
@ -58,8 +59,7 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
var marineTarballs = _context.MarineTarballs //error===========================================
|
||||
.Where(t => t.StationID != "1") // To remove unusable data with invalid stationID
|
||||
var marineTarballs = _context.MarineTarballs //ERRORRRRRRR======================================
|
||||
.Select(t => new
|
||||
{
|
||||
t.Id,
|
||||
@ -287,7 +287,7 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers
|
||||
WHERE marine.Id = @id";
|
||||
|
||||
var tarball = await _context.Database
|
||||
.SqlQueryRaw<TarballPdfDto>(query, new SqlParameter("@id", id))
|
||||
.SqlQueryRaw<TarballPdfDto>(query, new MySqlParameter("@id", id))
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (tarball == null)
|
||||
@ -413,31 +413,6 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
// Add this class outside your controller (e.g., in a DTOs folder)
|
||||
public class TarballPdfDto
|
||||
{
|
||||
public string StateName { get; set; }
|
||||
public string StationID { get; set; }
|
||||
public string LocationName { get; set; }
|
||||
public string Longitude { get; set; }
|
||||
public string Latitude { get; set; }
|
||||
public DateTime DateSample { get; set; }
|
||||
public TimeSpan TimeSample { get; set; }
|
||||
public string ClassifyID { get; set; }
|
||||
public int TarBallYes { get; set; } // SQL returns 1/0 for bits
|
||||
public int TarBallNo { get; set; }
|
||||
public int IsSand { get; set; }
|
||||
public int IsNonSandy { get; set; }
|
||||
public int IsCoquina { get; set; }
|
||||
public string OptionalName1 { get; set; }
|
||||
public string OptionalName2 { get; set; }
|
||||
public string OptionalName3 { get; set; }
|
||||
public string OptionalName4 { get; set; }
|
||||
public string FirstSampler { get; set; }
|
||||
public string FullName { get; set; }
|
||||
public string LevelName { get; set; }
|
||||
}
|
||||
|
||||
private bool IsImageValid(string imagePath)
|
||||
{
|
||||
try
|
||||
|
||||
@ -46,12 +46,16 @@ namespace PSTW_CentralSystem.DBContext
|
||||
entity.Property(e => e.OptionalName4).HasColumnName("optionalName4");
|
||||
entity.Property(e => e.Timestamp).HasColumnName("timestamp");
|
||||
|
||||
entity.HasOne(t => t.User)
|
||||
.WithMany()
|
||||
.HasForeignKey(t => t.FirstSampler)
|
||||
.HasPrincipalKey(u => u.FullName); // Assuming User has FullName
|
||||
|
||||
//Configure relationship with TarballStation
|
||||
entity.HasOne(m => m.MarineStation)
|
||||
.WithMany()
|
||||
.HasForeignKey(m => m.StationID)
|
||||
.HasPrincipalKey(t => t.StationID);
|
||||
|
||||
});
|
||||
|
||||
modelBuilder.Entity<MarineStation>(entity =>
|
||||
|
||||
@ -34,7 +34,7 @@ namespace PSTW_CentralSystem.Models
|
||||
[ForeignKey("StationID")]
|
||||
public required MarineStation MarineStation { get; set; }
|
||||
[ForeignKey("FirstSampler")]
|
||||
public required MarineStation User { get; set; }
|
||||
public required User User { get; set; }
|
||||
}
|
||||
|
||||
public class MarineStation
|
||||
|
||||
Loading…
Reference in New Issue
Block a user