EntityFramework DbContext Template Namespaces

I seem to be seeing something odd in EF. I have a working project that has a data model (.edmx) that was built from the database, with code generated using the DbContext template. The object model was then edited (introduction of inheritance, associations not in the database and some complex types). Still Working…

Ok, so the plan is: to drop the code generation and use the generated files as the basis for the object model.

A closer look at the files revealed this: the generated files were in the default namespace for the project the .edmx was in, not the proposed namespace in the .edmx properties.

namespace Repository;
{
    public partial class Order
...

Not really a big issue – change the namespace of the  files and edit the .edmx.

But when I look at the contents of the .edmx I see things like…

<EntityType Name="OrderListedInstrument" 
                    BaseType="ObjectModel.Order" 
                    Abstract="false" >

and

<Property Name="InstrumentSummary" 
                  Type="ObjectModel.InstrumentSummary" 
                  Nullable="false" />

Where Object model is the represents originally intended namespace.

How on earth does that work? Because it is working – is EF just ignoring the namespaces when it creates objects? There is no classes with those names in the given namespace…

This entry was posted in EF and tagged , . Bookmark the permalink.

Leave a Reply