I have a c# DbContext
defined like this:
public class DataContext : DbContext
{
public DbSet<Account> Accounts { get; set; }
...
}
In another place I have instance of DataContext
which I use to retrieve all
my Account
objects - and I expect many of them, but the code below:
var accountAll = context.Accounts.ToArray();
throws an exception:
System.TypeInitializationException: 'The type initializer for 'Microsoft.EntityFrameworkCore.Query.QueryableMethods' threw an exception.'
Inner Exception
InvalidOperationException: Sequence contains more than one matching element
Can someone understand why exception is thrown?
Class Account
:
using System;
using System.Collections.Generic;
namespace WebApi.Entities
{
public class Account
{
public int Id { get; set; }
public string Title { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string PasswordHash { get; set; }
public bool AcceptTerms { get; set; }
public Role Role { get; set; }
public string VerificationToken { get; set; }
public DateTime? Verified { get; set; }
public bool IsVerified => Verified.HasValue || PasswordReset.HasValue;
public string ResetToken { get; set; }
public DateTime? ResetTokenExpires { get; set; }
public DateTime? PasswordReset { get; set; }
public DateTime DOB { get; set; }
public DateTime Created { get; set; }
public DateTime? Updated { get; set; }
// Notification section
public bool NotifyWeekBefore { get; set; } = true;
public bool NotifyThreeDaysBefore { get; set; } = true;
// End of Notification section
public List<Schedule> Schedules { get; set; }
public List<Function> UserFunctions { get; set; }
public List<RefreshToken> RefreshTokens { get; set; }
public bool OwnsToken(string token)
{
return this.RefreshTokens?.Find(x => x.Token == token) != null;
}
}
}