1

I've created a Model using Model first and Entity Data Model of Entity Framework. Well, when I want to create the controller (right click on controllers folder Add->controller->WebApi 2 Controller with actions using EF) then I become after defining the inputfields an error message: there was an error getting the type "WebApi.Models.QR_Name". Try rebuilding the project. The same error getting by the other Model class. How can I solve this??


EDIT:

I have two classes: //Group

namespace WebApi.Models
{
    public partial class QR_Group
    {
        public QR_Group()
        {
            this.QR_Name = new HashSet<QR_Name>();
        }

        public int Id { get; set; }
        public string name { get; set; }
        public string code { get; set; }

        public virtual ICollection<QR_Name> QR_Name { get; set; }
    }
}

//Name

namespace WebApi.Models
{
    public partial class QR_Name
    {
        public int Id { get; set; }
        public string firstname { get; set; }
        public double maxAge { get; set; }
        public int QR_GroupId { get; set; }

        public virtual QR_Group QR_Group { get; set; }
    }
}

Additionally is here the Context class:

namespace WebApi.Models
{
    public partial class WebApiContext : DbContext
    {
        public WebApiContext()
            : base("name=WebApiContext")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

        public virtual DbSet<QR_Group> QR_Groups { get; set; }
        public virtual DbSet<QR_Name> QR_Names { get; set; }
    }
}
yuro
  • 2,189
  • 6
  • 40
  • 76
  • I'm afraid this does not provide enough information, for a exact answer. What You Can do - is read the 'Output' and 'Error' panes carefully. Usually they provide more details about the problem – Marty Jun 28 '15 at 11:31
  • @Marty What kind of details do you need? I'm only getting the error sentence. That's it.. I have 2 classes who have an association. Wait I will edit my post. – yuro Jun 28 '15 at 11:41
  • @Marty I've edited my Post. You can see the code. – yuro Jun 28 '15 at 11:46
  • Does the project build fine ? Are You able to read and write data to the DB using this 'Model' ? – Marty Jun 28 '15 at 11:51
  • @Marty I cannot read and write data to the DB when I haven't a Controller. I want to create the Controller but I'm getting the error. – yuro Jun 28 '15 at 11:54
  • Write a unit test :) – Marty Jun 28 '15 at 12:11

1 Answers1

1

Before creating your controller, press Ctrl+Shift+B to build your solution or go to 'Build->Build Solution' and then try creating your controller.