Specifically I am trying to scaffold WebAPI controllers using the Microsoft scaffolding, WebAPI 2.1, MVC 5.1.1 and Visual Studio 2013 Update 2 RC. I've noticed that when I try to add a mapping file like below in the context then I get error messages only when the scaffold runs. I have tried everything I can think of but I still get the messages when adding a line like this:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new AnswerMap());
Giving me the following error message in a dialog box after the scaffolding has spent 10 or more seconds doing something:
Error
There was an error running the selected code generator:
'Exception has been thrown by the target of an invocation'
Checking for causes of this on the web I see many different solutions but none help me. Most solutions to stop this error seem to involve, exiting, starting again, rebuilding or combinations of things. Some users seem to not be even able to solve the problem. If I cannot find out more information about what's wrong then it's really difficult.
Hope someone can point me to a place where I could find a log file or give me some suggestion as to how I could fix this problem.
Please note I already reviewed:
Visual Studio 2013 Scaffolding Error
Nothing here helps. I have reinstalled the scaffolding a few times. The problem goes away if I don't add the mapping file and comes back if I add it again. When I just use my context normally everything is okay.
Here's the code that I am using for the context
using Data.Mapping.Enum;
using Entities.Models.Enum;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Diagnostics;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using System.Web;
using Entities.Models.Core;
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations.Schema;
namespace WebRole1.Models
{
public partial class testCertContext1 : DbContext
{
public testCertContext1()
: base("name=testCertContext1")
{
}
public DbSet<Answer> Answers { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Configurations.Add(new AnswerMap2());
}
}
public class AnswerMap2 : EntityTypeConfiguration<Answer>
{
public AnswerMap2()
{
// Primary Key
this.HasKey(t => t.AnswerId);
// Identity
this.Property(t => t.AnswerId)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
// Table & Column Mappings
this.ToTable("Answer");
this.Property(t => t.AnswerId).HasColumnName("AnswerId");
this.Property(t => t.Text).HasColumnName("Text");
}
}
}