Entity Framework infrastructure object name and object name error

I have an ImporterState composite table bound to a table called Importer and State. The error is here context.Importers.Include(q => q.States). Why is this happening?

{"Invalid name for the Importers object.}}

    [Table("HeadlineWebsiteImport", Schema = "GrassrootsHoops")]
        public class Importer
        {
            public int Id { get; set; }
            public string Name { get; set; }
            public string RssUrl { get; set; }
            public string Type { get; set; }
            public string Keywords { get; set; }
            public bool Active { get; set; }
            public DateTime DateModified { get; set; }
            public DateTime DateCreated { get; set; }

            public int WebsiteId { get; set; }

            public HeadlineWebsite Website { get; set; }

            [InverseProperty("Importers")]
            public ICollection<State> States { get; set; }
        }

[Table("State", Schema = "GrassrootsHoops")]
    public class State
    {
        [Key]
        public int Id { get; set; }
        public string Name { get; set; }
        public string Abbr { get; set; }

        [InverseProperty("States")]
        public ICollection<Headline> Headlines { get; set; }

        [InverseProperty("States")]
        public ICollection<Importer> Importers { get; set; }
    }
+5
source share
1 answer

Many of the many cannot use attributes only.

try using something like:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Entity<Importer>()
            .HasMany(i => i.States)
            .WithMany(s => s.Importers)
            .Map(m =>
                {
                    m.MapLeftKey("ImporterId");
                    m.MapRightKey("StateId");
                    m.ToTable("ImporterState");
                });
    }
+8
source

All Articles