C# Core: No backing field could be found for property
Model:
public class User
{
public long Id { get; set; }
[JsonIgnore]
public LoginData LoginData { get; set; }
public User()
{
LoginData = new LoginData();
}
};
[Owned]
public class LoginData
{
public string Login { get; set; } = "";
public string Password { get; set; } = "";
public LoginData() { }
public LoginData(string Login, string Password)
{
this.Login = Login;
this.Password = Password;
}
}
OnModelCreating:
modelBuilder.Entity<User>().OwnsOne(p => p.LoginData, od => od.WithOwner());
In controller i try to use:
var users = await _context.User.Where(x => x.LoginData == loginData).ToListAsync();
And i get an error:
"No backing field could be found for property 'UserId' of entity type 'LoginData' and the property does not have a getter."
How can i fix it?