Not correct field removal in DataGridView



  • Working on an annex using Entity Framework when it occurs. When the data are downloaded from the table, the column ishand remains empty, although it has data.

    I'd show some screams, but I need at least 10 balls to load something here.

    If you change the data or add new fields, the table is updated and the column ishand is given the necessary value.

    I use the next code for initialization. where lb variable class of context Historys list with the floors from the table. HistorydataGridView datagridview where the data are downloaded

    lb.Historys.Load();
    HistorydataGridView.DataSource = lb.Historys.Local.ToBindingList();
    

    Table classes

    public class HistoryTabel
    {
        public int Id { get; set; }        
        public string book{get;set;}
        public int? isHandId { get; set; }
        public isHand ishand { get; set; }
        public string date { get; set; }
    }
    

    public class isHand
    {
    public int Id{get;set;}
    public string Name { get; set; }
    public virtual ICollection<HistoryTabel> History { get; set; }
    public isHand()
    {
    History = new List<HistoryTabel>();

    }
    public override string ToString()
    {
        return Name;
    }
    

    }

    context class

    public class LibraryContext : DbContext
    {
    public LibraryContext() : base("Library"){}

    public DbSet&lt;BookTable&gt; Books { get; set; }
    public DbSet&lt;AutorTable&gt; Autors { get; set; }
    public DbSet&lt;MagazineTable&gt; Magazines { get; set; }
    public DbSet&lt;HistoryTabel&gt; Historys { get; set; }
    public DbSet&lt;isHand&gt; hands { get; set; }
    

    }

    When I walk the debager, it says the count of hands is 0.
    How do you solve the problem?



  • Make your properties. ishand Virtual to use lazy load:

    public virtual isHand ishand { get; set; }
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2