В моем файле контекста есть следующее:
Код: Выделить всё
modelBuilder.Entity(entity =>
{
entity.ToTable("Request", "rmr");
entity.Property(e => e.CreatedOn).HasColumnType("datetime");
entity.Property(e => e.RaisedBy).HasMaxLength(256);
entity.Property(e => e.WorklistName).HasMaxLength(32);
});
modelBuilder.Entity(entity =>
{
entity.HasKey(e => new { e.RequestId, e.LineNumber })
.HasName("PK_RMR_REQUESTLINE");
entity.ToTable("RequestLine", "rmr");
entity.Property(e => e.Batch).HasMaxLength(32);
entity.Property(e => e.CancelBy).HasMaxLength(256);
entity.Property(e => e.CancelDate).HasColumnType("datetime");
entity.Property(e => e.CostCentre).HasMaxLength(32);
entity.Property(e => e.Destination).HasMaxLength(32);
entity.Property(e => e.FirstDeliveryDate).HasColumnType("datetime");
entity.Property(e => e.ProcessOrder).HasMaxLength(32);
entity.Property(e => e.Sku)
.HasMaxLength(32)
.HasColumnName("SKU");
entity.Property(e => e.SubmittedDate).HasColumnType("datetime");
entity.HasOne(d => d.Request)
.WithMany(p => p.RequestLines)
.HasForeignKey(d => d.RequestId)
.HasConstraintName("FK_RMR_REQUESTLINE_REQUEST");
});
Запрос:
Код: Выделить всё
public partial class Request
{
public Request()
{
RequestLines = new HashSet();
}
public long Id { get; set; }
public string RaisedBy { get; set; } = null!;
public DateTime CreatedOn { get; set; }
public string? WorklistName { get; set; }
public virtual ICollection RequestLines { get; set; }
}
Код: Выделить всё
public partial class RequestLine
{
public long RequestId { get; set; }
public int LineNumber { get; set; }
public string Sku { get; set; } = null!;
public string Batch { get; set; } = null!;
public int Quantity { get; set; }
public string? CostCentre { get; set; }
public string? ProcessOrder { get; set; }
public string Destination { get; set; } = null!;
public DateTime FirstDeliveryDate { get; set; }
public DateTime? SubmittedDate { get; set; }
public DateTime? CancelDate { get; set; }
public string? CancelBy { get; set; }
}
Код: Выделить всё
[HttpGet]
public async Task GetRequests()
{
if (_context.Requests == null)
{
return NotFound();
}
return await _context.Requests.ToListAsync();
}
Код: Выделить всё
[
{
"id": 0,
"raisedBy": "string",
"createdOn": "2022-06-15T17:32:27.129Z",
"worklistName": "string",
"requestLines": [
{
"requestId": 0,
"lineNumber": 0,
"sku": "string",
"batch": "string",
"quantity": 0,
"costCentre": "string",
"processOrder": "string",
"destination": "string",
"firstDeliveryDate": "2022-06-15T17:32:27.129Z",
"submittedDate": "2022-06-15T17:32:27.129Z",
"cancelDate": "2022-06-15T17:32:27.129Z",
"cancelBy": "string",
"request": "string"
}
]
}
]
Код: Выделить всё
[
{
"id": 1,
"raisedBy": "GEORGE",
"createdOn": "2022-06-13T13:14:31.813",
"worklistName": "WORKLIST1",
"requestLines": []
},
{
"id": 10008,
"raisedBy": "FFFFFF",
"createdOn": "2022-06-15T16:34:18.297",
"worklistName": "WORKLIST1",
"requestLines": []
}
]
Приносим извинения за длину вопрос. Если потребуется дополнительная информация, дайте мне знать.
Подробнее здесь: https://stackoverflow.com/questions/726 ... -sql-datab
Мобильная версия