I have 3 tables in my database and these are their EF models:
public class Customer
{
[Key]
public string Name { get; set; }
public string ContactID { get; set; }
public string VehicleID { get; set; }
public IList<Contact> Contacts { get; set; }
public IList<Vehicle> Vehicles { get; set; }
}
public class Vehicle
{
[Key]
public string VehicleID {get; set;}
public string Make {get; set;}
}
public class Contact
{
[Key]
public string ContactID {get; set;}
public string Name {get; set;}
}
The db context:
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<Customer>().HasKey(q => new { q.ContactID, q.VehicleID });
}
//Defining entities for context class
public DbSet<Contact> Contacts { get; set; }
public DbSet<Vehicle> Vehicles { get; set; }
public DbSet<Customer> Customers { get; set; }
In my controller:
public IEnumerable<Customer> GetCustomers()
{
return _context.Customer.Include(c => c.Contacts).Include(v => v.Vehicles);
}
My goal is to return data from the three tables but when I run this I get the error: SqlException: Invalid column name CustomerContactID CustomerVehicleID
Any help appreciated
Thanks!