'EFCore - Property is not loading at all
Ok, so I tried nearly everything so my last chance is to try to get help here :) As there is a lot smarter and maybe experienced people than myself.
Basically I have structure like this:
Configuration
SimulationConfiguration
MachineSimulation (typeof(SimulationSwitch))
Enabled (ENUM)
RobotSimulation (typeof(SimulationSwitch))
Enabled (ENUM)
...
(other parameters of class: Parameter.cs)
I though that it would be quite easy with the EF core. I created DbSets for each object
public DbSet<Configuration> Configurations { get; set; }
public DbSet<SimulationConfiguration> SimulationConfigurations { get; set; }
public DbSet<SimulationSwitch> SimulationSwitches { get; set; }
Also set some initialization in OnModelCreating()
Configuration
modelBuilder.Entity<Configuration>()
.HasOne(p => (SimulationConfiguration)p.SimulationConfiguration) //Cast due to Interface
.WithOne()
.HasForeignKey<SimulationConfiguration>(p => p.IdConfiguration);
SimulationConfiguration
modelBuilder.Entity<SimulationConfiguration>()
.HasOne<ConfigurationRobotLoader25>()
.WithOne(p => (SimulationConfiguration)p.SimulationConfiguration)
.HasForeignKey<SimulationConfiguration>(p => p.IdConfiguration);
SimulationSwitch
modelBuilder.Entity<SimulationSwitch>()
.Property(p => p.Enable)
.HasConversion<int>()
.HasDefaultValue(ESimulationMode.ACTIVE);
I have tried loading it as:
DatabaseContext.SimulationConfigurations
.Include(p => p.MachineSimulation)
.Include(p => p.RobotSimulation)
.FirstOrDefault(simConf => simConf.IdConfiguration == ConfigurationId);
but it is always empty. but only the SimulationSwitches are empty. Other Parameters load completely fine...
In image above you can see that the green rectangle was loaded fine (also with other properties that I didn't mention) But the red rectangle is some default value. (empty ID, INT value of INACTIVE is 1
I have the same structure with Parameter and it works perfectly fine. But the SimulationSwitches are always empty. (ID = 0)
I am loosing my mind over this. Also tried HasConversion() (and parse it as String) but nothing...
any help will be apreciated
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
