Closed ankitmatrix08 closed 2 years ago
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:
public partial interface IRoleFunction
{
long Id { get; }
string Name { get; }
bool IsActive { get; }
bool IsSystemDefined { get; }
string Description { get; }
}
public partial class ERoleFunction : IRoleFunction
{
public ERoleFunction() : base("RoleFunction")
{
}
long Id { get; set; }
string Name { get; set; }
bool IsActive { get; set; }
bool IsSystemDefined { get; set; }
string Description { get; set; }
}
public partial class BananaContext : DbContext
{
public BananaContext()
{
ChangeTracker.AutoDetectChangesEnabled = false;
}
public BananaContext(DbContextOptions<BananaContext> options)
{
}
public virtual DbSet<ERoleFunction> RoleFunctions { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration(new EntityConfigurations.RoleFunctionConfiguration());
}
}
public class RoleFunctionConfiguration
{
public override void Configure(EntityTypeBuilder<ERoleFunction> builder)
{
builder.ToTable("RoleFunctions");
builder.Property(e => e.Name).HasMaxLength(40);
builder.Property(e => e.Name).IsRequired();
builder.Property(e => e.IsActive).IsRequired();
builder.Property(e => e.IsSystemDefined).IsRequired();
builder.Property(e => e.Description).HasMaxLength(200);
}
}
Simple test code:
class Program
{
static BananaContext context = new BananaContext();
static void Main(string[] args)
{
var test = context.RoleFunctions.ToList();
}
}
Screen shots from both the packages:
1. Preview5
2. Preview4
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 ToArrayAsync
.
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);
}
}
I experience the sam. I upgraded from version 6 to 7 Preview 5. Never had a problem before.
Just to double check - when you revert the package from 7_Preview5 to 6, do you see the exception go away? Since in my case it vanishes when I revert to 7_Preview4.
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);
}
}
Unhandled exception. System.InvalidOperationException: Sequence contains no elements
at System.Linq.ThrowHelper.ThrowNoElementsException()
at System.Linq.Enumerable.Aggregate[TSource](IEnumerable`1 source, Func`3 func)
at Microsoft.EntityFrameworkCore.Query.RelationalEntityShaperExpression.GenerateMaterializationCondition(IEntityType entityType, Boolean nullable)
at Microsoft.EntityFrameworkCore.Query.EntityShaperExpression..ctor(IEntityType entityType, Expression valueBufferExpression, Boolean nullable, LambdaExpression materializationCondition)
at Microsoft.EntityFrameworkCore.Query.RelationalEntityShaperExpression..ctor(IEntityType entityType, Expression valueBufferExpression, Boolean nullable)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.SharedTypeEntityExpandingExpressionVisitor.TryExpand(Expression source, MemberIdentity member)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.SharedTypeEntityExpandingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.IncludeExpression.VisitChildren(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.VisitExtension(Expression node)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.SharedTypeEntityExpandingExpressionVisitor.VisitExtension(Expression extensionExpression)
at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.IncludeExpression.VisitChildren(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.VisitExtension(Expression node)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.SharedTypeEntityExpandingExpressionVisitor.VisitExtension(Expression extensionExpression)
at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.SharedTypeEntityExpandingExpressionVisitor.Expand(SelectExpression selectExpression, Expression lambdaBody)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.ExpandSharedTypeEntities(SelectExpression selectExpression, Expression lambdaBody)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.RemapLambdaBody(ShapedQueryExpression shapedQueryExpression, LambdaExpression lambdaExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateSelect(ShapedQueryExpression source, LambdaExpression selector)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
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__DisplayClass12_0`1.<ExecuteAsync>b__0()
at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.GetAsyncEnumerator(CancellationToken cancellationToken)
at System.Runtime.CompilerServices.ConfiguredCancelableAsyncEnumerable`1.GetAsyncEnumerator()
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToArrayAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
at Program.Main() in C:\local\code\AllTogetherNow\Daily\Daily.cs:line 202
at Program.<Main>()
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