Can the [ObservableProperty] attribute and [NotMapped] attribute of DBContext be combined in .NET MAUI?

  Kiến thức lập trình

I have the issue, that I want parts of my code be notified of changes if an object is selected. However, the corresponding DBContext object should not map the property to a column in the database. Can this behaviour be combined?

Model class:

public partial class Answer : ObservableObject
{
    [Key]
    public int AnswerId { get; set; }
    public int QuestionId { get; set; }
    public string Content { get; set; }
    [ObservableProperty]
    private bool _isCorrect;
    public int? Points { get; set; }

// important part
    [ObservableProperty]
    [NotMapped]
    public bool _isSelected;
}

The problem is, I receive the error that ‘IsSelected’ is an invalid column name. Does the [NotMapped] attribute not apply on the generated parts?

LEAVE A COMMENT