'The related table couldn't be load with other related table

I have problem with a related tables in SQLite database. Database create by code (CodeFirst). And I using EFCore for working with database.

enter image description here

I have next classes (Please, have attention to the Client property):

public partial class Firmwares
{
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    [Key]
    public int Id { get; set; }

    public int ControlBlockTypesId { get; set; }
    public ControlBlockTypes ControlBlockType { get; set; }

    public int ControlBlockProducersId { get; set; }
    public ControlBlockProducers ControlBlockProducer { get; set; }

    public int CategoriesId { get; set; }
    public Categories Category { get; set; }

    public string SerialNumber { get; set; }

    public string Hardware { get; set; }

    public string Software { get; set; }

    public DateTime CreateDate { get; set; }

    public int ClientsId { get; set; }
    public Clients Client { get; set; }

    public string FileName { get; set; }

    public string Comment { get; set; }
}

public class Clients
{
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    [Key]
    public int Id { get; set; }
    public string FullName { get; set; }
    public string PhoneNumber { get; set; }
    public DateTime YearOfCar { get; set; }
    public string VINCode { get; set; }
    public ICollection<Firmwares> Firmware { get; set; }
}

And next model creator (removed other table creators):

protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Clients>().ToTable("Clients");
        modelBuilder.Entity<Firmwares>().ToTable("Firmwares");
    }

And when I try get list of Firmwares, there is Client equal null.

I tried to change declaration of ForeignKeys (by the attribute in the class, in the ModelBuilder and how it in code). But it didn't help.

How I get the list of Firmwares:

        IQueryable<Firmwares> searchingFirmwares;
        switch (SearchingParametr)
        {
            case "Search.ClientPhone": { searchingFirmwares = MainWindow.Database.Firmwares.Where(w => w.Client.PhoneNumber.Contains(Text)); break; }
            default: { searchingFirmwares = MainWindow.Database.Firmwares; break; }
        }

        SearchingFirmwares = searchingFirmwares.Include(w=>w.Client).ToList();

I read that it can be a Lazy Loading. But Include method didn't helped too.

But when I drop the database, create again and fill it with a test data, it's work - the Client isn't empty. After rebooting application, Client is empty again.

Can anybody help me with this problem? Maybe some advices? Some other ways to try?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source