-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sequence contains no elements 7.0.0-preview.5.22302.2 #28247
Comments
This issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate. |
@ajcvickers Although, for me it was quite a straight forward case - as the same code (models, context, tests) ran in Preview4 but after upgrading the new package (build and then run) fails in Preview5, but please find the below sample for your investigation: NOTE: This exception does not occurs for all the entities -- I am yet to find a pattern but as all of the entities does work with Preview4 hence it cannot be a case with my code. Models:
Simple test code:
Screen shots from both the packages: |
The code is not compile-able, Even if I make corrections to it, it works fine for me. You need to share full runnable repro code. Also make sure you are not using mismatching versions. |
I experience the same. I upgraded from version 6 to 7 Preview 5. Never had a problem before. |
Here is my query. It fails on This is my personal project. Dealing with requesting tax refunds for domestic services in Sweden. So no sensitive stuff. var query = _context.RotRutCases
.AsSplitQuery()
.AsNoTracking()
.OrderByDescending(x => x.Id)
.AsQueryable();
int totalItems = await query.CountAsync(cancellationToken);
query = query
.Skip(request.Page * request.PageSize)
.Take(request.PageSize);
var items = await query.ToArrayAsync(cancellationToken); This is the model: public class RotRutCase : AuditableEntity
{
private RotRutCase()
{
}
public RotRutCase(DomesticServiceKind kind, string buyer, DateTime paymentDate, decimal laborCost, decimal paidAmount, decimal requestedAmount, int invoiceId, decimal otherCosts, double hours, decimal materialCost, decimal? receivedAmount)
{
Kind = kind;
Status = RotRutCaseStatus.Created;
Buyer = buyer;
PaymentDate = paymentDate;
LaborCost = laborCost;
PaidAmount = paidAmount;
RequestedAmount = requestedAmount;
InvoiceId = invoiceId;
OtherCosts = otherCosts;
Hours = hours;
MaterialCost = materialCost;
ReceivedAmount = receivedAmount;
}
public int Id { get; private set; }
public RotRutRequest? Request { get; private set; }
public DomesticServiceKind Kind { get; private set; }
public RotRutCaseStatus Status { get; set; }
public string Buyer { get; private set; }
public DateTime PaymentDate { get; private set; }
public decimal LaborCost { get; private set; }
public decimal PaidAmount { get; private set; }
public decimal RequestedAmount { get; private set; }
public int InvoiceId { get; private set; }
public decimal OtherCosts { get; private set; }
public double Hours { get; private set; }
public decimal MaterialCost { get; private set; }
public decimal? ReceivedAmount { get; set; }
public Rot? Rot { get; set; }
public Rut? Rut { get; set; }
}
public class Rot
{
public HomeRepairAndMaintenanceServiceType? ServiceType { get; set; }
public string? PropertyDesignation { get; set; }
public string? ApartmentNo { get; set; }
public string? OrganizationNo { get; set; }
}
public class Rut
{
public HouseholdServiceType? ServiceType { get; set; }
}
public enum RotRutCaseStatus
{
Created,
InvoicePaid,
RequestSent,
RequestConfirmed
}
public class RotRutRequest : AuditableEntity
{
private readonly List<RotRutCase> _cases = new List<RotRutCase>();
public int Id { get; private set; }
public string Description { get; private set; } = null!;
public RotRutRequestStatus Status { get; private set; }
public IReadOnlyCollection<RotRutCase> Cases => _cases;
public void AddCase(RotRutCase @case)
{
_cases.Add(@case);
}
}
public enum RotRutRequestStatus
{
Created,
Sent,
Confirmed
} Configuration: public class RotRutCaseConfiguration : IEntityTypeConfiguration<RotRutCase>
{
public void Configure(EntityTypeBuilder<RotRutCase> builder)
{
builder.ToTable("RotRutCases");
builder.OwnsOne(x => x.Rot);
builder.OwnsOne(x => x.Rut);
}
} |
Just to double check - when you revert the package from 7_Preview5 to 6, do you see the exception go away? |
BTW. This is the exception that I get: [rotrutservice_924fe26a-4]: info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
[rotrutservice_924fe26a-4]: Entity Framework Core 7.0.0-preview.5.22302.2 initialized 'RotRutContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer:7.0.0-preview.5.22302.2' with options: SensitiveDataLoggingEnabled
[rotrutservice_924fe26a-4]: info: Microsoft.EntityFrameworkCore.Database.Command[20101]
[rotrutservice_924fe26a-4]: Executed DbCommand (19ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
[rotrutservice_924fe26a-4]: SELECT COUNT(*)
[rotrutservice_924fe26a-4]: FROM [RotRutCases] AS [r]
[rotrutservice_924fe26a-4]: fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
[rotrutservice_924fe26a-4]: An unhandled exception has occurred while executing the request.
[rotrutservice_924fe26a-4]: System.InvalidOperationException: Sequence contains no elements
[rotrutservice_924fe26a-4]: at System.Linq.ThrowHelper.ThrowNoElementsException()
[rotrutservice_924fe26a-4]: at System.Linq.Enumerable.Aggregate[TSource](IEnumerable`1 source, Func`3 func)
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.Query.RelationalEntityShaperExpression.GenerateMaterializationCondition(IEntityType entityType, Boolean nullable)
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.Query.EntityShaperExpression..ctor(IEntityType entityType, Expression valueBufferExpression, Boolean nullable, LambdaExpression materializationCondition)
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.Query.RelationalEntityShaperExpression..ctor(IEntityType entityType, Expression valueBufferExpression, Boolean nullable)
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.SharedTypeEntityExpandingExpressionVisitor.TryExpand(Expression source, MemberIdentity member)
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.SharedTypeEntityExpandingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.Query.IncludeExpression.VisitChildren(ExpressionVisitor visitor)
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.SharedTypeEntityExpandingExpressionVisitor.VisitExtension(Expression extensionExpression)
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.Query.IncludeExpression.VisitChildren(ExpressionVisitor visitor)
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.SharedTypeEntityExpandingExpressionVisitor.VisitExtension(Expression extensionExpression)
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.SharedTypeEntityExpandingExpressionVisitor.Expand(SelectExpression selectExpression, Expression lambdaBody)
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.ExpandSharedTypeEntities(SelectExpression selectExpression, Expression lambdaBody)
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.RemapLambdaBody(ShapedQueryExpression shapedQueryExpression, LambdaExpression lambdaExpression)
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateSelect(ShapedQueryExpression source, LambdaExpression selector)
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass12_0`1.<ExecuteAsync>b__0()
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken)
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.GetAsyncEnumerator(CancellationToken cancellationToken)
[rotrutservice_924fe26a-4]: at System.Runtime.CompilerServices.ConfiguredCancelableAsyncEnumerable`1.GetAsyncEnumerator()
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
[rotrutservice_924fe26a-4]: at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToArrayAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
[rotrutservice_924fe26a-4]: at YourBrand.RotRutService.Application.Queries.GetCases.Handler.Handle(GetCases request, CancellationToken cancellationToken) in /Users/marina/Projects/YourBrand/Finance/RotRutService/RotRutService/Application/Queries/GetCases.cs:line 61
[rotrutservice_924fe26a-4]: at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
[rotrutservice_924fe26a-4]: at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
[rotrutservice_924fe26a-4]: at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
[rotrutservice_924fe26a-4]: at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
[rotrutservice_924fe26a-4]: at MediatR.Pipeline.RequestPostProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
[rotrutservice_924fe26a-4]: at MediatR.Pipeline.RequestPreProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
[rotrutservice_924fe26a-4]: at YourBrand.RotRutService.Controllers.CasesController.GetCases(Int32 page, Int32 pageSize, Nullable`1 kind, RotRutCaseStatus[] status, CancellationToken cancellationToken) in /Users/marina/Projects/YourBrand/Finance/RotRutService/RotRutService/Controllers/CasesController.cs:line 25
[rotrutservice_924fe26a-4]: at lambda_method9(Closure, Object)
[rotrutservice_924fe26a-4]: at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
[rotrutservice_924fe26a-4]: at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Logged|12_1(ControllerActionInvoker invoker)
[rotrutservice_924fe26a-4]: at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
[rotrutservice_924fe26a-4]: at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
[rotrutservice_924fe26a-4]: at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
[rotrutservice_924fe26a-4]: at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
[rotrutservice_924fe26a-4]: at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
[rotrutservice_924fe26a-4]: at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
[rotrutservice_924fe26a-4]: at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
[rotrutservice_924fe26a-4]: at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
[rotrutservice_924fe26a-4]: at NSwag.AspNetCore.Middlewares.SwaggerUiIndexMiddleware.Invoke(HttpContext context)
[rotrutservice_924fe26a-4]: at NSwag.AspNetCore.Middlewares.RedirectToIndexMiddleware.Invoke(HttpContext context)
[rotrutservice_924fe26a-4]: at NSwag.AspNetCore.Middlewares.OpenApiDocumentMiddleware.Invoke(HttpContext context)
[rotrutservice_924fe26a-4]: at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) |
Here are some updates: I expected it had to do with the owned entities, as per the configuration: public void Configure(EntityTypeBuilder<RotRutCase> builder)
{
builder.ToTable("RotRutCases");
builder.OwnsOne(x => x.Rot);
builder.OwnsOne(x => x.Rut);
} So I disabled them. If ignore both of the properties (removing the owned properties) it all works. public void Configure(EntityTypeBuilder<RotRutCase> builder)
{
builder.ToTable("RotRutCases");
builder.Ignore(x => x.Rot);
builder.Ignore(x => x.Rut);
} |
@smitpatel Here's a full repro. Fails on preview 5 and latest daily build. #nullable enable
public static class Your
{
public static string ConnectionString = @"Data Source=(LocalDb)\MSSQLLocalDB;Database=SixOh";
}
public class SomeDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer(Your.ConnectionString)
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
public DbSet<RotRutCase> RotRutCases { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
new RotRutCaseConfiguration().Configure(modelBuilder.Entity<RotRutCase>());
}
}
public class Program
{
public static async Task Main()
{
var request = new Request();
using (var context = new SomeDbContext())
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
var query = context.RotRutCases
.AsSplitQuery()
.AsNoTracking()
.OrderByDescending(x => x.Id)
.AsQueryable();
int totalItems = await query.CountAsync();
query = query
.Skip(request.Page * request.PageSize)
.Take(request.PageSize);
var items = await query.ToArrayAsync();
}
}
public class Request
{
public int Page { get; set; }
public int PageSize { get; set; }
}
public class RotRutCase
{
private RotRutCase()
{
}
public RotRutCase(DomesticServiceKind kind, string buyer, DateTime paymentDate, decimal laborCost, decimal paidAmount, decimal requestedAmount, int invoiceId, decimal otherCosts, double hours, decimal materialCost, decimal? receivedAmount)
{
Kind = kind;
Status = RotRutCaseStatus.Created;
Buyer = buyer;
PaymentDate = paymentDate;
LaborCost = laborCost;
PaidAmount = paidAmount;
RequestedAmount = requestedAmount;
InvoiceId = invoiceId;
OtherCosts = otherCosts;
Hours = hours;
MaterialCost = materialCost;
ReceivedAmount = receivedAmount;
}
public int Id { get; private set; }
public RotRutRequest? Request { get; private set; }
public DomesticServiceKind Kind { get; private set; }
public RotRutCaseStatus Status { get; set; }
public string Buyer { get; private set; }
public DateTime PaymentDate { get; private set; }
public decimal LaborCost { get; private set; }
public decimal PaidAmount { get; private set; }
public decimal RequestedAmount { get; private set; }
public int InvoiceId { get; private set; }
public decimal OtherCosts { get; private set; }
public double Hours { get; private set; }
public decimal MaterialCost { get; private set; }
public decimal? ReceivedAmount { get; set; }
public Rot? Rot { get; set; }
public Rut? Rut { get; set; }
}
public enum DomesticServiceKind
{
}
public class Rot
{
public HomeRepairAndMaintenanceServiceType? ServiceType { get; set; }
public string? PropertyDesignation { get; set; }
public string? ApartmentNo { get; set; }
public string? OrganizationNo { get; set; }
}
public enum HomeRepairAndMaintenanceServiceType
{
}
public class Rut
{
public HouseholdServiceType? ServiceType { get; set; }
}
public enum HouseholdServiceType
{
}
public enum RotRutCaseStatus
{
Created,
InvoicePaid,
RequestSent,
RequestConfirmed
}
public class RotRutRequest
{
private readonly List<RotRutCase> _cases = new List<RotRutCase>();
public int Id { get; private set; }
public string Description { get; private set; } = null!;
public RotRutRequestStatus Status { get; private set; }
public IReadOnlyCollection<RotRutCase> Cases => _cases;
public void AddCase(RotRutCase @case)
{
_cases.Add(@case);
}
}
public enum RotRutRequestStatus
{
Created,
Sent,
Confirmed
}
public class RotRutCaseConfiguration : IEntityTypeConfiguration<RotRutCase>
{
public void Configure(EntityTypeBuilder<RotRutCase> builder)
{
builder.ToTable("RotRutCases");
builder.OwnsOne(x => x.Rot);
builder.OwnsOne(x => x.Rut);
}
}
|
Notes from triage: we should add back the code that creates a null instance in this case. |
@ajcvickers So is this going to get fixed as a patch for Preview5? Since there were good amount of fixes done and I am unable to verify some of them due to above issue? |
@ankitmatrix08 we don't patch preview versions - this will be fixed in a later preview. |
@ankitmatrix08 @marinasundstrom A workaround here is to make the dependent required: builder.OwnsOne(x => x.Rot);
builder.Navigation(x => x.Rot).IsRequired();
builder.OwnsOne(x => x.Rut);
builder.Navigation(x => x.Rut).IsRequired(); |
@ajcvickers It worked as a workaround which is acceptable. Though it assigns instances of the owned entities to both of the properties even though they in some cases technically are null. I managed to get around that in my DTO mappings by checking a property (Kind) used as a discriminator. Thanks! |
After doing an upgrade to EFCore v7_Preview5 - most of our entities are not getting materialized and throwing exception "InvalidOperationException: Sequence contains no elements" as below:
NOTE When I reverted the package back to preview-4 all of the exceptions vanished.
Is the latest preview release buggy?
Stack Trace:
EF Core version: 7.0.0-preview.5.22302.2
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system: Win 10
IDE: Visual Studio Professional 2022 (64-bit) Version 17.2.4
The text was updated successfully, but these errors were encountered: