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; }
    }
}
6
  • 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 Commented Jun 28, 2015 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. Commented Jun 28, 2015 at 11:41
  • @Marty I've edited my Post. You can see the code. Commented Jun 28, 2015 at 11:46
  • Does the project build fine ? Are You able to read and write data to the DB using this 'Model' ? Commented Jun 28, 2015 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. Commented Jun 28, 2015 at 11:54

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.