// r:"nuget:Microsoft.EntityFrameworkCore.Sqlite,8.0.5"
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System.ComponentModel.DataAnnotations;
using System.Text.Json;
const string connectionString = "DataSource=test";
await using var services = new ServiceCollection()
.AddDbContext<TestDbContext>(options =>
{
options.UseSqlite(connectionString);
})
.BuildServiceProvider()
;
await using var scope = services.CreateAsyncScope();
var dbContext = scope.ServiceProvider.GetRequiredService<TestDbContext>();
await dbContext.Database.EnsureDeletedAsync();
await dbContext.Database.EnsureCreatedAsync();
var job = new Job() { Title = "test" };
dbContext.Jobs.Add(job);
await dbContext.SaveChangesAsync();
job.Title = "test2";
await dbContext.SaveChangesAsync();
try
{
var jobs = dbContext.Jobs.ToArray();
Console.WriteLine(JsonSerializer.Serialize(jobs));
}
catch (Exception e)
{
Console.WriteLine(e);
}
file sealed class TestDbContext(DbContextOptions<TestDbContext> options) : DbContext(options)
{
public DbSet<Job> Jobs { get; set; } = default!;
}
file sealed class Job
{
public int Id { get; set; }
[StringLength(120)]
public required string Title { get; set; }
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset UpdatedAt { get; set; }
}
Include stack traces
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.CreateNavigationExpansionExpression(Expression sourceExpression, IEntityType entityType)
at Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.VisitExtension(Expression extensionExpression)
at Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.Expand(Expression query)
at Microsoft.EntityFrameworkCore.Query.QueryTranslationPreprocessor.Process(Expression query)
at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass9_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.GetEnumerator()
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.System.Collections.Generic.IEnumerable<TEntity>.GetEnumerator()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
Include verbose output
Please include --verbose output when filing bugs about the dotnet ef or Package Manager Console tools.
Use triple-tick fences for tool output. For example:
C:\Stuff\AllTogetherNow\FiveOh>dotnet ef dbcontext list --verbose
Using project 'C:\Stuff\AllTogetherNow\FiveOh\FiveOh.csproj'.
...
Finding DbContext classes in the project...
Found DbContext 'BlogContext'.
BlogContext
Include provider and version information
EF Core version: 8.0.0/8.0.5/8.0.6
Database provider: Microsoft.EntityFrameworkCore.Sqlite
Target framework: .NET 8.0
Operating system: Windows
IDE: Rider and dotnet-cli
File a bug
Include your code
Include stack traces
Include verbose output
Please include
--verbose
output when filing bugs about thedotnet ef
or Package Manager Console tools.Use triple-tick fences for tool output. For example:
Include provider and version information
EF Core version: 8.0.0/8.0.5/8.0.6 Database provider:
Microsoft.EntityFrameworkCore.Sqlite
Target framework: .NET 8.0 Operating system: Windows IDE: Rider and dotnet-cli