Entity Framework Core HasOne and WithMany doesn’t exist

.net-core asp.net-core-mvc c# entity-framework entity-framework-core

Question

Why could I haven’t HasOne() and WithMany() parameters in modelBiulder.Entity<T> method?

1
0
4/11/2020 10:18:41 AM

Popular Answer

I have that but it still show me a warning

public class CarEquipment
{

    public int CarId { get; set; }
    public int EquipmentId { get; set; }

    public Car Car { get; set; }
    public Equipment Equipment { get; set; }
}

public class Equipment
{
    public int EquipmentId { get; set; }
    public IEnumerable<string> Item { get; set; }
    public List<CarEquipment> CarEquipments { get; set; }
}
public class
{
    public int CarId { get; set; }
    public string Brand { get; set; }
    public string Model { get; set; }
    public int Price { get; set; }

    public List<CarEquipment> CarEquipments { get; set; }
}

public DbSet<Car> Cars { get; set; }
    public DbSet<Equipment> Equipments { get; set; }
    public DbSet<CarEquipment> CarEquipments { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Car>().HasKey(x => x.CarId);
        modelBuilder.Entity<CarEquipment>().HasKey(x => new { x.CarId, x.EquipmentId });
        modelBuilder.Entity<Equipment>().HasKey(x => x.EquipmentId);
        modelBuilder.Entity<CarEquipment>().HasOne(x => x.Equipment).WithMany(x => x.CarEquipments);
        modelBuilder.Entity<CarEquipment>().HasOne(x => x.Car).WithMany(x => x.CarEquipments);
    }
0
4/11/2020 10:43:29 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow