Cannot create controller with Entity framework - Unable to retrieve metadata

前端 未结 7 1988
慢半拍i
慢半拍i 2021-02-12 20:35

I\'m using VS2013

When I try to create an \"MVC 5 Controller with views using entity Framework\" I get the following error:

the         


        
相关标签:
7条回答
  • 2021-02-12 21:19

    If you trying to create a Odata controller

    Go to DbContext class and then check whether

    public System.Data.Entity.DbSet<BackEnd.Models.OrganizationType> YourModel{ get; set; }

    Available ior not

    If yes .. remove it and then retry

    0 讨论(0)
  • 2021-02-12 21:20

    Re-Try after deleting below line from your EFDbContext class.

    public System.Data.Entity.DbSet<WebApplication.Domain.Entities.Product> Products { get; set; }
    

    Example:

    0 讨论(0)
  • 2021-02-12 21:28

    For me, I have to "run custom tool" by right click on model.tt and model.context.tt files, then error got resolved.

    0 讨论(0)
  • 2021-02-12 21:28

    Problem may be because of missing [NotMapped] Attribute in one of the model class.

    As I missed the attribute and I was cunning my head.

    [Display(Name="Logo")]
    [DataType(DataType.Upload)]
    [NotMapped]
    public HttpPostedFileBase Logo { set; get; }
    
    0 讨论(0)
  • 2021-02-12 21:32

    In my case, but using VS 2017, this occurred when I had all my model classes defined within a single .cs file. Once I separated each class out into its own file the generation process completed correctly.

    0 讨论(0)
  • 2021-02-12 21:36
    public class EFDbContext : DbContext
    {
        public DbSet<Product> Products { get; set; }
    }
    

    Forgot the { get; set; }... all works now #crying

    0 讨论(0)
提交回复
热议问题