2

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:enter image description here

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");

   }

2
  • what happens if you change Tags from string[] to just a string? Commented Nov 3 at 22:03
  • It's always the basics, isn't it? That was the problem. If you want to post that as an answer, I'll give you the check mark. Commented Nov 3 at 22:40

1 Answer 1

3

you have Tags defined as an array

public string[] Tags { get; set; }

but in the db it's a single value

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.