Add Controller Model Classes not shown

后端 未结 14 750
天命终不由人
天命终不由人 2020-12-31 09:41

I managed to create a Model First DBContext model (before it was a normal ObjectContext derived model).

Strangly now my VS is not showing ANY of my classes in the Mo

相关标签:
14条回答
  • 2020-12-31 10:13

    Had the same problem. I fixed it.

    • Separate the EF in another class library project.
    • add reference in main web project.
    • add the connection string in web project config file.
    0 讨论(0)
  • 2020-12-31 10:13

    This problem can occur when you have a project referencing another project. This is called a transitive project reference and manifests in a number of ways, one of which is this. You need to directly reference projects and not transitively to resolve this in some cases.

    eg: Project A , project B, Project C

    Project B has a reference to C so in repos/b/bin/debug you have b.dll and c.dll Project A needs both so you point the reference to B.dll and C.dll in the b/bin/debug folder. If you do this you can't see any models from c.dll but you can see the b.dll models.

    fix/workaround: reference repos/b/bin/debug/b.dll and repos/c/bin/debug/c.dll directly

    0 讨论(0)
  • 2020-12-31 10:15

    Finally I managed to get the scaffolding working again. I refactored my model.edmx out of the main project. The templating stuff will now generate the model classes in this new model project. After adding the model project to the main project, the classes are showing up in the controller model selectbox again. Strange as it seems to work in a completely new set-up solution without separation...

    0 讨论(0)
  • 2020-12-31 10:16

    "Add Controller" Model Classes not shown for scaffolding

    Environment Used: ASP.NET MVC5 using C# Visual Studio 2013

    Solution 1: If solution name is SAME as project name, just clean solution, Build Solution. It will work.

    Solution 2: If solution name is DIFFERENT from project name, then check below steps:

    (i) Check your model class(s) namespace as

    namespace SolutionName.ProjectName.Models
    { ...}
    

    suppose solution name is "WGT" and project name is "MS", then models class say User should be

    namespace WGT.MS.Models
    { public class User{...}}
    

    (ii) After this, clear solution.

    (iii) Build Solution

    It will surely work. Found this solution after spending a lot of time. It's a practical and implemented solution.

    0 讨论(0)
  • 2020-12-31 10:18

    I got the same issue , Check the package (asp.net mvc, & EF ) compatibility , upgrade all nuget packages. clean and Rebuild project. That works for me.

    http://forums.asp.net/t/1791616.aspx?Can+t+create+new+controller+No+model+classes+are+available+

    0 讨论(0)
  • 2020-12-31 10:21

    I had this same issue with one specific model. I was using .Net Core 2.x with EF Core. Turned out it was because it was inheriting a class which was, in turn, inheriting Microsoft.AspNetCore.Identity.IdentityUser. EF Core will not let me scaffold from that model. I removed the inheritance of IdentityUser from the base class and the model appeared in the dropdown for EF new Controller.

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