I have two POCO objects:
public class Product
{
public int ProductID { get; set; }
public string Name { get; set; }
public int CategoryID { get; set; }
public virtual Category Category { get; set; }
}
public class Category
{
public int CategoryID { get; set; }
public string Name { get; set; }
}
So obviously, when I create a Product, I can select a category for that product. Or rather, a category is required.
I can’t create a product without explicitly selecting a category, and my data is structured in such a way, that I don’t want to create a “No Category” category entry.
I’ve thought about doing a many-to-many mapping between these two tables… but would like to avoid it if possible.
Either I’m doing something silly, or there really is no way to do this.
Any help would be appreciated!
Make the
CategoryIDnullable. If you do not supply value forCategoryIDit will be set toNULLin database.