Model
class Tag
{
public int Id { get; set; }
public string Name { get; set;}
public IEnumerable<TagAttribute> TagAttributes => _tagAttributes.AsReadOnly();
private List<TagAttribute> tagAttributes;
}
class TagAttribute
{
public int Id { get; set; }
public string Value{ get; set;}
public int TagId { get; set; }
}
I have followed the documentation to configure a backing field
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// This works
//var t = modelBuilder.Entity<Tag>().Metadata.FindNavigation(nameof(Tag.TagAttributes));
//t.SetPropertyAccessMode(PropertyAccessMode.Field);
// This does not
modelBuilder.Entity<Tag>()
.Property(q => q.TagAttributes)
.HasField("tagAttributes")
.UsePropertyAccessMode(PropertyAccessMode.Field);
}
Can anyone explain what the difference is in these methods, please?
This is the error I receive when using the 2nd method to configure the backing field...
System.InvalidOperationException: 'The property 'Tag.TagAttributes' is of type 'IEnumerable' which is not supported by current database provider. Either change the property CLR type or ignore the property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.'