I've set up Entity Framework Code First with the Generic Repository Pattern.
Here are my models:
public interface IEntity {
int Key { get; set; }
}
public class Product : IEntity {
public int Key {
get {
return ID;
}
set {
ID = value;
}
}
public int ID { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public IEnumerable<Category> Category { get; set; }
}
public class Category : IEntity {
public int Key {
get {
return ID;
}
set {
ID = value;
}
}
public int ID { get; set; }
public string Name { get; set; }
public int ParentID { get; set; }
}
Here is my context that hooks into my generic repo:
public class EntitiesContext : DbContext, IDbContext {
public DbSet<Product> Products { get; set; }
public new IDbSet<T> Set<T>() where T : class {
return base.Set<T>();
}
}
As you can see Product has a IEnumerable of Category. If I were to create a database to match this is would be like so:
Product - ID - Name - etc.
Category - ID - Name - etc.
ProductCategories - ProductID - CategoryID
How come when my database is created that there is no joining table?