-
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
Context.FirstOrDefault throws ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index #14911
Comments
This works in 3.1 SELECT [a].[Id], [t].[Id], [t7].[FirstValueObjectAggregateId], [t7].[Id], [t7].[FirstValueObjectAggregateId0], [t7].[Id0], [t7].[FourthValueObjectSecondValueObjectFirstValueObjectAggregateId], [t7].[FourthValueObjectSecondValueObjectId], [t7].[Id1], [t7].[AnyValue], [t7].[SecondValueObjectFirstValueObjectAggregateId], [t7].[SecondValueObjectId], [t7].[Id2], [t7].[SecondValueObjectFirstValueObjectAggregateId0], [t7].[SecondValueObjectId0], [t7].[Id00], [t7].[FourthValueObjectThirdValueObjectSecondValueObjectFirstValueObjectAggregateId], [t7].[FourthValueObjectThirdValueObjectSecondValueObjectId], [t7].[FourthValueObjectThirdValueObjectId], [t7].[Id10], [t7].[AnyValue0]
FROM [Aggregates] AS [a]
LEFT JOIN (
SELECT [a0].[Id], [a1].[Id] AS [Id0]
FROM [Aggregates] AS [a0]
INNER JOIN [Aggregates] AS [a1] ON [a0].[Id] = [a1].[Id]
) AS [t] ON [a].[Id] = [t].[Id]
LEFT JOIN (
SELECT [s].[FirstValueObjectAggregateId], [s].[Id], [t0].[FirstValueObjectAggregateId] AS [FirstValueObjectAggregateId0], [t0].[Id] AS [Id0], [s2].[FourthValueObjectSecondValueObjectFirstValueObjectAggregateId], [s2].[FourthValueObjectSecondValueObjectId], [s2].[Id] AS [Id1], [s2].[AnyValue], [t6].[SecondValueObjectFirstValueObjectAggregateId], [t6].[SecondValueObjectId], [t6].[Id] AS [Id2], [t6].[SecondValueObjectFirstValueObjectAggregateId0], [t6].[SecondValueObjectId0], [t6].[Id0] AS [Id00], [t6].[FourthValueObjectThirdValueObjectSecondValueObjectFirstValueObjectAggregateId], [t6].[FourthValueObjectThirdValueObjectSecondValueObjectId], [t6].[FourthValueObjectThirdValueObjectId], [t6].[Id1] AS [Id10], [t6].[AnyValue] AS [AnyValue0]
FROM [SecondValueObject] AS [s]
LEFT JOIN (
SELECT [s0].[FirstValueObjectAggregateId], [s0].[Id], [s1].[FirstValueObjectAggregateId] AS [FirstValueObjectAggregateId0], [s1].[Id] AS [Id0]
FROM [SecondValueObject] AS [s0]
INNER JOIN [SecondValueObject] AS [s1] ON ([s0].[FirstValueObjectAggregateId] = [s1].[FirstValueObjectAggregateId]) AND ([s0].[Id] = [s1].[Id])
) AS [t0] ON ([s].[FirstValueObjectAggregateId] = [t0].[FirstValueObjectAggregateId]) AND ([s].[Id] = [t0].[Id])
LEFT JOIN [SecondValueObject_FifthValueObjects] AS [s2] ON ([t0].[FirstValueObjectAggregateId] = [s2].[FourthValueObjectSecondValueObjectFirstValueObjectAggregateId]) AND ([t0].[Id] = [s2].[FourthValueObjectSecondValueObjectId])
LEFT JOIN (
SELECT [t1].[SecondValueObjectFirstValueObjectAggregateId], [t1].[SecondValueObjectId], [t1].[Id], [t4].[SecondValueObjectFirstValueObjectAggregateId] AS [SecondValueObjectFirstValueObjectAggregateId0], [t4].[SecondValueObjectId] AS [SecondValueObjectId0], [t4].[Id] AS [Id0], [t5].[FourthValueObjectThirdValueObjectSecondValueObjectFirstValueObjectAggregateId], [t5].[FourthValueObjectThirdValueObjectSecondValueObjectId], [t5].[FourthValueObjectThirdValueObjectId], [t5].[Id] AS [Id1], [t5].[AnyValue]
FROM [ThirdValueObject] AS [t1]
LEFT JOIN (
SELECT [t2].[SecondValueObjectFirstValueObjectAggregateId], [t2].[SecondValueObjectId], [t2].[Id], [t3].[SecondValueObjectFirstValueObjectAggregateId] AS [SecondValueObjectFirstValueObjectAggregateId0], [t3].[SecondValueObjectId] AS [SecondValueObjectId0], [t3].[Id] AS [Id0]
FROM [ThirdValueObject] AS [t2]
INNER JOIN [ThirdValueObject] AS [t3] ON (([t2].[SecondValueObjectFirstValueObjectAggregateId] = [t3].[SecondValueObjectFirstValueObjectAggregateId]) AND ([t2].[SecondValueObjectId] = [t3].[SecondValueObjectId])) AND ([t2].[Id] = [t3].[Id])
) AS [t4] ON (([t1].[SecondValueObjectFirstValueObjectAggregateId] = [t4].[SecondValueObjectFirstValueObjectAggregateId]) AND ([t1].[SecondValueObjectId] = [t4].[SecondValueObjectId])) AND ([t1].[Id] = [t4].[Id])
LEFT JOIN [ThirdValueObject_FifthValueObjects] AS [t5] ON (([t4].[SecondValueObjectFirstValueObjectAggregateId] = [t5].[FourthValueObjectThirdValueObjectSecondValueObjectFirstValueObjectAggregateId]) AND ([t4].[SecondValueObjectId] = [t5].[FourthValueObjectThirdValueObjectSecondValueObjectId])) AND ([t4].[Id] = [t5].[FourthValueObjectThirdValueObjectId])
) AS [t6] ON ([s].[FirstValueObjectAggregateId] = [t6].[SecondValueObjectFirstValueObjectAggregateId]) AND ([s].[Id] = [t6].[SecondValueObjectId])
) AS [t7] ON [t].[Id] = [t7].[FirstValueObjectAggregateId]
ORDER BY [a].[Id], [t7].[FirstValueObjectAggregateId], [t7].[Id], [t7].[FourthValueObjectSecondValueObjectFirstValueObjectAggregateId], [t7].[FourthValueObjectSecondValueObjectId], [t7].[Id1], [t7].[SecondValueObjectFirstValueObjectAggregateId], [t7].[SecondValueObjectId], [t7].[Id2], [t7].[FourthValueObjectThirdValueObjectSecondValueObjectFirstValueObjectAggregateId], [t7].[FourthValueObjectThirdValueObjectSecondValueObjectId], [t7].[FourthValueObjectThirdValueObjectId], [t7].[Id10] |
We encounter similar issue while using OData. We updated from dotnet 2.2 to 3.1 today. Our model looks like this: public class CommentEntity {
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key]
public virtual Guid Id { get; set; }
[...]
}
public class OrderEntity {
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key]
public virtual Guid Id { get; set; }
[...]
}
public class CustomerEntity {
[... id, collections, etc..]
public virtual ICollection<CommentEntity> Comments { get; set; }
public virtual ICollection<OrderEntity> Orders { get; set; }
public CustomerEntity() {
Comments = new HashSet<CommentEntity>();
Orders = new HashSet<OrderEntity>();
}
} We determined that the issue is while accessing two or more collections at the same time. If we want to access two lists at the same time, we get following exception:
We also found, that if we try to fetch 3 or more lists at the same time, we get another exception:
We are not sure if that's an issue with OData, or with LINQ or with EFCore. Best regards, |
@TheAifam5 - Please file a new issue with full repro code. This issue has been fixed 3.1 and pending committing a regression test to code base. |
@smitpatel I am aware of that PR. Last time I checked was in review state. |
@TheAifam5 - There is no PR associated. I am referring to comment I have posted here #14911 (comment) |
Fixed in #22282 |
I have a model similar to this one :
Then I get the mentioned exception when try to read from the Aggregate entity :
context.Aggregates.FirstOrDefault()
I created a repo you can use to repreduce the issue
here is the error message with the stack trace
The text was updated successfully, but these errors were encountered: