The entity type
You need to specify mappings for your entities:
public class MealsContext: DbContext
{
public MealsContext() : base("ConnectionString")
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// mappings
}
public DbSet<Meal> Meals{ get; set; }
public DbSet<Meat> Meats{ get; set; }
public DbSet<Vegetable> Vegetables { get; set; }
public DbSet<Drink> Drinks{ get; set; }
}
I had the same problem until I started using Entity Framework Power Tools
Using it you can generate clear entities like a business objects and mapping classes. Good article that helped me to create amazing data access layer: Reverse Engineer Code First
Solved.
The first half was my oversight. The second half... well I don't have a word for what was wrong. It is not really a bug, or incompatibility, but something very inconvenient, intermittent and hard to figure out. First a summary, and then the length explanation for those who care:
The conceptual model was built using the EdmxWriter
to parse the DbContext
and its underlying pieces.
The model then was used to generate SQL scripts to push the schema to a new database. The trick is, the database is Oracle.
Oracle is a baby and does not accept long column names. So the generated EDMX and SQL Scripts had to be modified to build and map parts of the conceptual model to truncated column names.
Not really a big deal. It works fine. So where did things go wrong?
Oracle does not support "code first". And even though it was done manually, using the EdmxWriter
constitutes a code-first approach in Oracle's eyes. So when the first EDMX schema was parsed, it bitched about boolean mappings. The solution was to temporarily remove the bools from my C# models, add them to the EDMX manually and make the web.config mapping Oracle suggests (mapping bool
to NUMBER(1,0)
).
Everything is groovy again. But why does it keep reoccurring?
At different times throughout the development process some ends of the agreement - either C#, EDMX, or Oracle - are altered. And each time, it seems the columns were automatically remapped and I was unaware. If the EDMX model was refreshed from Oracle, the mappings were pointing to C# properties that didn't exist (the short column names). If the model was refreshed from C# code the mappings were not preserved and they attempted to map to long column names that weren't in Oracle.
The bummer with this approach (sort of hybrid code first and model first) is if I want to continue managing my own models and handle customizations necessary for Oracle's little baby attitude, I have to be very careful and monitor the hell out of the EDMX file.