Generating code from an existing database EF7 - asp.net

I'm trying to generate code from my database but i get errors : System.AggregateException: One or more errors occurred. ---> Method not found
this is my project.json:
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-beta5",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta7",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta5",
"EntityFramework.SqlServer": "7.0.0-beta8-15797",
"EntityFramework.Commands": "7.0.0-beta8-15797",
"EntityFramework.SqlServer.Design": "7.0.0-beta8-15797",
"Remotion.Linq": "2.0.0-rc-001"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
]
}
How do i Generating code from an existing database EF7
I'm using this command :
dnx ef dbcontext scaffold "ConnectionString" EntityFramework.SqlServer
Thank you.

Upgrade all packages to be consistent. You have beta5 and beta 8 mixed. If you still experience errors, please check or file and issue to the appropriate repository. https://github.com/aspnet

Related

Dependencies not supporting DNXCore Framework version and namespaces not found errors

I created a brand new ASP.NET Web API project from scratch. I selected an ASP.NET v5 blank Template and added nothing. My default project.json file looked like so:
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
]
}
I then went to the NuGET package installer and added Microsoft.AspNet.WebApi and straight away I am presented with errors in the compiler:
I am finding this is occurring for a lot of packages I am trying to install (even the Microsoft.AspNet.WebApi.HelpPage package gives me the same errors). I am also trying to add DbModelBuilder to my classes which throws similar results (which makes me think something is corrupt somewhere):
My updated project.json file now looks like this:
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"EntityFramework.Core": "7.0.0-rc1-final",
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.WebApi": "5.2.3"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
},
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.Data.Entity": "4.0.0.0"
}
},
"dnxcore50": { }
},
"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
]
}
As I am setting this up a a brand new project, I am a little confused as to what I am doing wrong or if my installation of Visual Studio is messed up. It's making it impossible to follow any tutorials online due to all the errors I'm faced with.
Any help would be greatly appreciated.

System.InvalidOperationException: Unable to resolve service for type 'Microsoft.Framework.Runtime.ILibraryManager'

I have the following project.json file...
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"EntityFramework.Commands": "7.0.0-beta5",
"EntityFramework.SqlServer": "7.0.0-beta5",
"Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta5",
"Microsoft.AspNet.Diagnostics": "1.0.0-beta5",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta5",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta5",
"Microsoft.AspNet.Mvc": "6.0.0-beta5",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta5",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-beta5",
"Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta5",
"Microsoft.Framework.Configuration.Json": "1.0.0-beta5",
"Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta5"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini",
"ef": "EntityFramework.Commands",
"gen": "Microsoft.Framework.CodeGeneration"
},
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.Data": "4.0.0.0"
}
},
"dnxcore50": { }
},
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
]
}
I am trying now to do some MVC 6 Controller Scaffolding in command line but after executing the command:
dnx gen controller -name ClassController --dataContext
RegistrationDbContext --model Class
However, I am getting the following error message...
EDIT: This is the message that I am getting after installing Microsoft.Framework.CodeGeneration package (Install-Package Microsoft.Framework.CodeGeneration -Pre)
System.InvalidOperationException: Unable to resolve service for type 'Microsoft.Framework.Runtime.ILibraryManager' while attempting to activate 'Microsoft.Framework.CodeGeneration.DefaultCodeGeneratorAssemblyProvider'.
at Microsoft.Framework.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
at Microsoft.Framework.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
at Microsoft.Framework.DependencyInjection.ActivatorUtilities.CreateInstance[T](IServiceProviderprovider, Object[] parameters)
at Microsoft.Framework.CodeGeneration.ServiceProvider.AddServiceWithDependencies[TService,TImplementation]()
at Microsoft.Framework.CodeGeneration.Program.AddCodeGenerationServices(ServiceProvider serviceProvider)
at Microsoft.Framework.CodeGeneration.Program..ctor(IServiceProvider serviceProvider)
Any pointers? How can I fix that?
In any case, this is my global.json too..
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-beta5",
"runtime": "clr",
"architecture": "x64"
}
}
Thanks!
In rc1-final, the namespaces have changed :
FROM: Microsoft.Framework.CodeGeneration
TO: Microsoft.Extensions.CodeGeneration
project.json
"dependencies": {
...
"Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final",
}
"commands": {
...
"gen": "Microsoft.Extensions.CodeGeneration"
}
To customize the MVC6 scaffolding templates, you will find them in the folder: C:\Users\{user}\.dnx\packages\Microsoft.Extensions.CodeGenerators.Mvc\1.0.0-rc1-final\Templates
Use dnx gen controller --help to get some help on the parameters

Adding reference to Class Library issue in ASP.NET 5 beta 7

I removed dnxcore50 from project.json and added an empty class library to solution. When I add reference to class library, project build correctly but when I want to publish project, I will get this error:
The expected lock file doesn't exist. Please run "dnu restore" to generate a new lock file
dnu restore command also not helps.
If i remove reference to class library, publish works fine.
project.json:
{
"webroot": "wwwroot",
"userSecretsId": "aspnet5-AdsProject-e7d42575-2bc4-4316-881a-236435c407a1",
"version": "1.0.0-*",
"dependencies": {
"EntityFramework.Commands": "7.0.0-beta7",
"EntityFramework.SqlServer": "7.0.0-beta7",
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta7",
"Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta7",
"Microsoft.AspNet.Authentication.Google": "1.0.0-beta7",
"Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta7",
"Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta7",
"Microsoft.AspNet.Diagnostics": "1.0.0-beta7",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta7",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta7",
"Microsoft.AspNet.Mvc": "6.0.0-beta7",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta7",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta7",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta7",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta7",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-beta7",
"Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta7",
"Microsoft.Framework.Configuration.Json": "1.0.0-beta7",
"Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta7",
"Microsoft.Framework.Logging": "1.0.0-beta7",
"Microsoft.Framework.Logging.Console": "1.0.0-beta7",
"Microsoft.Framework.Logging.Debug" : "1.0.0-beta7",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta7"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"dnx451": {
"dependencies": {
"ClassLibrary": "1.0.0-*"
}
}
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"scripts": {
"prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
}
}
Be sure you resolved all reference warnings and don't mix different beta versions.
Are both versions still in beta7 incl your visual studio??
Try upgrade to beta 8 all projects, dnvm,dnx and visual studio
See the home repro
I know this is a bit late. I had the exact same issue on beta 7 today. And only with custom libs added.
I got it fixed by going into the folder called "wrap" that gets created when you add your library. In there you'll find a project.json. Run a dnu restore on that folder in cmd.
Worked like a charm for me.

EF7: dnx ef command error "Value can not be Null"

When I use the command
dnx ef
the following error occurs:
C:\Users\Livio\OneDrive\Informatik\Websites\HomeNetwork\src\HomeNetwork.API>dnx ef
System.ArgumentNullException: Value cannot be null.
Parameter name: appEnv
at Microsoft.Data.Entity.Utilities.Check.NotNull[T](T value, String parameterName)
at Microsoft.Data.Entity.Commands.Program..ctor(IServiceProvider > serviceProvider, IApplicationEnvironment appEnv, ILibraryManager libraryManager, > IRuntimeEnvironment runtimeEnv)
I'm using dnvm 1.0.0-beta8 coreclr x86.
My project.json looks like this (in HomeNetwork.API)
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-beta5",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta5",
"EntityFramework.SqlServer": "7.0.0-beta5",
"EntityFramework.Commands": "7.0.0-beta5"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
]
}
I created this project without editing the code, expect adding the EF7 Dependency.
I'm using dnvm 1.0.0-beta8 coreclr x86.
Then, you should use the beta8 versions of the dependencies:
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-beta8",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta8",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta8",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta8",
"EntityFramework.SqlServer": "7.0.0-beta8",
"EntityFramework.Commands": "7.0.0-beta8"
}

why my asp.net project look like references not resolved?

Running VS 2015 RC on windows 7 64, for the asp.net projects, it looks like the screenshot below, there is also no intellisense, but the project can compile, something wrong?
the VS has resharper 9 and web essential extension installed as well
project.json
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Server.IIS": "1.0.0-beta4",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta4",
//"Microsoft.AspNet.Mvc": "6.0.0-beta4"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
]
}
also, was keep getting the error message
the activitylog.xml
They aren't missing, they are just not used. If they were missing/unresolved, there would be a red squiggle. They are dimmed because you aren't using them.
See this: http://csharp.2000things.com/2014/10/28/1213-visual-studio-2014-unused-using-statements-greyed-out/
Try this for the other issues:
Run VS with /SafeMode switch (eliminates the extension issues and possible conflicts with VS)
Uncomment the "Microsoft.AspNet.Mvc": "6.0.0-beta4" line in the dependencies file

Resources