I am making a Web API with .Net and it is receiving a custom JSON object from a web form to serialize to the model. I am currently having an issue displaying the API response. I am storing the data in an in memory database at first just to get it working.
I am not sure why it is asking me for a primary key despite there being a key defined on my model.
My next step is to add multipart-form data but that is its own can of worms.
The error happens on the _context.ProjectItems.ToListAsync(); line.
I have already added an ID to the model.
[Required]
[Key]
public new long Id { get; set; }
[HttpGet("{id}")]
public async Task<ActionResult<ProjectItem>> GetProjectItem(long id)
{
var projectItem = await _context.ProjectItems.FindAsync(id);
if (projectItem == null)
{
return NotFound();
}
return projectItem;
}
[HttpGet]
public async Task<ActionResult<IEnumerable<ProjectItem>>>
GetProjectItems()
{
return await _context.ProjectItems.ToListAsync();
}
My model: ProjectItem.cs using System.ComponentModel.DataAnnotations;
namespace RupAPI.Controllers
{
public class ProjectItem : Project
{
[Required]
[Key]
public new long Id { get; set; }
public string ProjName { get; set; }
public DateTime DateSub { get; set; }
public DateTime DueDate { get; set; }
public DateTime ArrivalDate { get; set; }
public string Desc { get; set; }
public Array Sku { get; set; }
public Array SkuDesc { get; set; }
public Array Item { get; set; }
public Array ItemDesc { get; set; }
public Array FileName { get; set; }
public new byte[] File { get; set; }
}
}
An unhandled exception occurred while processing the request. InvalidOperationException: The entity type 'Array' requires a primary key to be defined.
Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.ValidateNonNullPrimaryKeys(IModel model)
Stack Query Cookies Headers
InvalidOperationException: The entity type 'Array' requires a primary key to be defined.
+
return await _context.ProjectItems.ToListAsync();
lambda_method(Closure , object )
Aucun commentaire:
Enregistrer un commentaire