2

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'.'

Luiso
  • 4,173
  • 2
  • 37
  • 60
Phil
  • 1,609
  • 12
  • 24
  • change `private List tagAttributes;` property to `private ICollection tagAttributes;` – Divyesh patel Oct 10 '19 at 09:25
  • may all ready answered [Model Containing a IEnumerable property insert using entityFramework Ask](https://stackoverflow.com/questions/30219634/model-containing-a-ienumerable-property-insert-using-entityframework) – Divyesh patel Oct 10 '19 at 09:26

0 Answers0