I just got my .Net 9 Maui app working with EF Core and SQLite. I have one row of data in the database that looks like this:
I have a simple query that runs when the app loads. The repository method is this
public void GetMoviesAsync()
{
try
{
using (var movieContext = new MovieContext())
{
var movies = movieContext.Movies
.AsNoTracking()
.ToList<Movie>();
//return movies ?? new List<Movie>();
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
When the EF query runs, it throws an error: 'N' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0. which is being thrown from
Exception thrown: 'System.Text.Json.JsonReaderException' in System.Text.Json.dll
Exception thrown: 'System.Text.Json.JsonReaderException' in Microsoft.EntityFrameworkCore.Relational.dll
I can only assume that the SQLite response comes back to EF as JSON? I can't figure out what that bad character "N" is.
I also tried running it as raw sql movieContext.Database.ExecuteSqlRaw("Select * From Movies"); which returned a -1, so no rows returned.
Here is the Movie class:
public class Movie
{
[Key]
public int MovieId { get; set; }
[Required]
public string Title { get; set; }
public DateOnly ReleaseDate { get; set; }
public string Genre { get; set; }
public string[] Tags { get; set; }
public string MovieLocation { get; set; }
public string ImageLocation { get; set; }
public int GroupId { get; set; }
}
And the data context
public class MovieContext : DbContext
{
public DbSet<Movie> Movies { get; set; }
public DbSet<Group> Groups { get; set; }
public MovieContext()
{
SQLitePCL.Batteries_V2.Init();
this.Database.EnsureCreated();
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) =>
optionsBuilder.UseSqlite("Data Source = D:\\Repos\\MovieManager\\MovieManager.db3");
}
Tagsfromstring[]to just astring?