Reference external enum type using EntityObject Generator Template

317 Views Asked by At

I have the following enum:

namespace Common
{
    public enum VehicleType
    {
        Car=10,
        Bike=20
    }
}

I have created a reference enum type in EF designer with the name VehicleType referencing Common.VehicleType. The edmx is in the Models namespace so i end up with two different enums:

Common.VehicleType
Models.VehicleType

To set the enum on an entity object instance i need to cast it:

Vehicle vehicle = new Vehicle();
vehicle.VehicleType = (Models.VehicleType)Common.VehicleType.Bike;

There are a couple of problems with this:

  1. I need to use fully qualified names (the names of the enums must be the same from what i gather).
  2. I need to cast everywhere.
  3. I will get a circular reference since the Models namespace references Common and Common now needs to reference Models in order to cast.

This is a simplified explanation. I can't change the references or the generator template since that would amount to massive code changes in a quite large project.

I guess its the generation template screwing things up. Is there any way to get around this?

EDIT

Fields with type VehicleType generated by EntityObject template generator become:

private VehicleType _VehicleType;

where VehicleType is Models.VehicleType

0

There are 0 best solutions below