Question

So I've got a Deeply connected POCO that I've written using EF5/Code First, it has one-to-one, and one-to-many relationships with a number of classes and Enum properties for things like Gender, AddressType and so on.

A very simplified view:

public class Contact
{
   public string FullName { get; set; }

   public string Title { get; set;

   public GenderEnum Gender { get; set; }

   public Country CountryOfBirth { get; set; }

   public string Address { get; set; }
}

I've got a DbContext for this Object and the others, and it also creates a lot of Seed data for the Country list and the various other things I need to represent.

However, when I come to use MvcScaffolding like so:

Scaffold Controller Model.Contact -Repository -DbContext Model.Context

It creates a _CreateOrEdit.cshtml view that shows the String fields from my Contact model, but doesn't provide a drop down list for the Enums, or any of the related classes.

So, How do I tell MvcScaffolding that the DataType for a specific property can be loaded from the Context, or do I need to do this manually ?

Was it helpful?

Solution 2

Actually turned out to be a lot simpler.

What I'd done was just use Class relationships and whilst Entity Framework was happy enough with that, MvcScaffolding didn't recognize the relationships.

Once I'd added a backing Id field and a ForeignKey attribute to the actual type, MvcScaffolding picked it straight up.

OTHER TIPS

I think you cannot specify that in the command line, but you can always use a customized template. Check this Steven Anderson post

One of the nicest things is that you just create the custom template on the CodeTemplates directory and it will become available automatically, and it will become available to your team if you add the file your the source control

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top