-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Closed
Labels
Description
Type of issue
Other (describe below)
Description
I'm working on writing a Blazor app using .NET 8. I've got a database with column names that have embedded whitespace. When I deserialize it all the numeric values (SMALLINT in a SQL Server database) are 0 (for example the column "Video Number"), which is wrong and doesn't correctly show what's in the table. However, when I check the values using Swagger, it is perfectly correct. I had thought that the attribute JsonPropertyName would resolve my issue, but it doesn't. Here's my class
public partial class Entry
{
[Key, Column("Video Number", Order = 0)]
[JsonPropertyName("Video Number")]
public short VideoNumber { get; set; }
[Key, Column("Entry", Order = 1)]
public byte Entry1 { get; set; }
[Required]
public short ShowCode { get; set; }
[Required]
public string EpisodeName { get; set; } = null!;
public DateTime? ActualPlayTime { get; set; }
public bool Completed { get; set; }
public string? Comment { get; set; }
public TimeOnly? ActualPlayTime1 { get; set; }
public virtual Show Show { get; set; } = null!;
public virtual Video VideoNumberNavigation { get; set; } = null!;
}And here's the code snippet where I'm trying to read the data out of the table:
var contentStream = await httpResponse.Content.ReadAsStreamAsync();
var bozo = await System.Text.Json.JsonSerializer.DeserializeAsync<Entry[]>(contentStream, new System.Text.Json.JsonSerializerOptions { DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull, PropertyNameCaseInsensitive = true });
return bozo;Page URL
Content source URL
Document Version Independent Id
27c18218-d28f-a524-b7e1-8262005b7026
Article author
Metadata
- ID: 7bee4ecb-7464-b321-937a-e6d4586556eb
- Service: dotnet-fundamentals