Hi All,
I'm using X# Core and I'm trying to do a very basic exercice that you can find here:
http://www.entityframeworktutorial.net/ ... ation.aspx.
(I've no problems when I do this exercice using C#. Maybe it's only a connection string problem ?)
Problem occurs when i apply: add-migration CreateSchoolDB
I get the following error:
"Constructor not found. Unable to find an appropriate constructor for the type System.Runtime.Versioning.FrameworkName."
(I've not the problem when I do it in C#)
NuGet packages are installed
Install-Package Microsoft.EntityFrameworkCore.SqlServer
Install-Package Microsoft.EntityFrameworkCore.Tools
About using:
USING System
USING System.Collections.Generic
USING System.Linq
USING System.Data.Linq
USING system.data.SqlClient
USING System.Text
USING System.Threading.Tasks
USING Microsoft.EntityFrameworkCore
USING Microsoft.EntityFrameworkCore.Design
I created the following classes from the c# code:
CLASS Student
PUBLIC PROPERTY StudentID AS INT AUTO
PUBLIC PROPERTY Name AS STRING AUTO
CONSTRUCTOR()
RETURN
END CLASS
CLASS Course
PUBLIC PROPERTY CourseID AS INT AUTO
PUBLIC PROPERTY CourseName AS STRING AUTO
CONSTRUCTOR()
RETURN
END CLASS
CLASS SchoolContext INHERIT DbContext
PUBLIC PROPERTY Students AS DbSet<Student> AUTO
PUBLIC PROPERTY Courses AS DbSet<Course> AUTO
PROTECTED OVERRIDE METHOD OnConfiguring( optionsBuilder AS DbContextOptionsBuilder) AS VOID
LOCAL cString AS STRING
cString:= e"Server=.SQLEXPRESS;Database=SchoolDB;Trusted_Connection=True;"
optionsBuilder.useSqlServer(cString)
END CLASS
Is the connection string ok?
in c#:
optionsBuilder.UseSqlServer(@"Server=.SQLEXPRESS;Database=SchoolDB;Trusted_Connection=True;")
I tried with:
e"Server=.SQLEXPRESS;Database=SchoolDB;Trusted_Connection=True;"
"Server=.SQLEXPRESS;Database=SchoolDB;Trusted_Connection=True;"
"Server=localhostSQLEXPRESS;Database=SchoolDB;Trusted_Connection=True;"
Thank you
Guy DEPREZ
EntityFrameworkCore. Basic exercice. Problem with add-migration.
- lumberjack
- Posts: 729
- Joined: Fri Sep 25, 2015 3:11 pm
- Location: South Africa
EntityFrameworkCore. Basic exercice. Problem with add-migration.
Hi Guy,
Just add a CONSTRUCTOR to your SchoolContext class.
If you look at the previous chapter in that link you will see there is a constructor for that class in the example.
Regards,
Johan
Just add a CONSTRUCTOR to your SchoolContext class.
If you look at the previous chapter in that link you will see there is a constructor for that class in the example.
Regards,
Johan
______________________
Johan Nel
Boshof, South Africa
Johan Nel
Boshof, South Africa
EntityFrameworkCore. Basic exercice. Problem with add-migration.
Guy
Remove the e prefix for the connection string. This is not needed and will cause the S in the strings to be interpreted as a control character The @ notation in C# is the same as our normal strings.
Robert
Remove the e prefix for the connection string. This is not needed and will cause the S in the strings to be interpreted as a control character The @ notation in C# is the same as our normal strings.
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
EntityFrameworkCore. Basic exercice. Problem with add-migration.
Thank you Johan and Robert.
But problem not yet solved. Same error with add-migration
My last changes to the class:
CLASS SchoolContext INHERIT DbContext
PUBLIC PROPERTY Students AS DbSet<Student> AUTO
PUBLIC PROPERTY Courses AS DbSet<Course> AUTO
CONSTRUCTOR() AS VOID
SUPER()
RETURN
PROTECTED OVERRIDE METHOD OnConfiguring( optionsBuilder AS DbContextOptionsBuilder) AS VOID
LOCAL oString AS STRING
SUPER:OnConfiguring(optionsBuilder)
oString:= "Server=.SQLEXPRESS;Database=SchoolDB;Trusted_Connection=True;"
optionsBuilder.useSqlServer(oString)
PROTECTED OVERRIDE METHOD OnModelCreating(oModelBuilder AS ModelBuilder) AS VOID
SUPER:OnModelCreating(oModelBuilder)
END CLASS
Guy
But problem not yet solved. Same error with add-migration
My last changes to the class:
CLASS SchoolContext INHERIT DbContext
PUBLIC PROPERTY Students AS DbSet<Student> AUTO
PUBLIC PROPERTY Courses AS DbSet<Course> AUTO
CONSTRUCTOR() AS VOID
SUPER()
RETURN
PROTECTED OVERRIDE METHOD OnConfiguring( optionsBuilder AS DbContextOptionsBuilder) AS VOID
LOCAL oString AS STRING
SUPER:OnConfiguring(optionsBuilder)
oString:= "Server=.SQLEXPRESS;Database=SchoolDB;Trusted_Connection=True;"
optionsBuilder.useSqlServer(oString)
PROTECTED OVERRIDE METHOD OnModelCreating(oModelBuilder AS ModelBuilder) AS VOID
SUPER:OnModelCreating(oModelBuilder)
END CLASS
Guy
-
- Posts: 248
- Joined: Fri Oct 14, 2016 7:09 am
EntityFrameworkCore. Basic exercice. Problem with add-migration.
A stab in the dark, but if you have more than one project in your solution you'll need to specify the default project in the Package Manager Console.
If there was a problem with the connection string I think it would tell you. You can always be more specific in the add-migration call...
This is for EF6, but I imagine it's the same or similar for EF core.
HTH
Nick
If there was a problem with the connection string I think it would tell you. You can always be more specific in the add-migration call...
Code: Select all
Add-Migration -StartUpProjectName "MyProjectName" -ConnectionString "Data Source=NICK-PORTABLECIOSQLEXPRESS;Initial Catalog=MyDB;Integrated Security=True;Persist Security Info=True;MultipleActiveResultSets=True" -ConnectionProviderName "System.Data.SqlClient" MyMigrationName
HTH
Nick
EntityFrameworkCore. Basic exercice. Problem with add-migration.
Thank you Nick
There is something new... It occurs only once by following your suggestion...
Look at the path.... below (in red). It's a assembly /exe path problem...After ....bindebug, it restarts with the full path
PM> Add-migration -Name "CreateSchoolDB" -Context "SchoolContext" -Project "EFCTutorials" -debug -verbose
Using project ''.
Using startup project ''.
Build started...
Build succeeded.
E:Visual Studio 2017X Sharp SolutionsEFCTutorialspackagesMicrosoft.EntityFrameworkCore.Tools.2.1.0toolsnet461anyef.exe migrations add CreateSchoolDB --json --context SchoolContext --verbose --no-color --prefix-output --assembly "E:Visual Studio 2017X Sharp SolutionsEFCTutorialsEFCTutorialsbinDebugE:Visual Studio 2017X Sharp SolutionsEFCTutorialsEFCTutorialsbinDebugEFCTutorials.exe" --startup-assembly "E:Visual Studio 2017X Sharp SolutionsEFCTutorialsEFCTutorialsbinDebugE:Visual Studio 2017X Sharp SolutionsEFCTutorialsEFCTutorialsbinDebugEFCTutorials.exe" --project-dir "E:Visual Studio 2017X Sharp SolutionsEFCTutorialsEFCTutorials" --language XSharp --working-dir "E:Visual Studio 2017X Sharp SolutionsEFCTutorials" --root-namespace EFCTutorials
System.NotSupportedException: Le format du chemin d'accès donné n'est pas pris en charge.
à System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)
à System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
à Microsoft.EntityFrameworkCore.Tools.OperationExecutorBase..ctor(String assembly, String startupAssembly, String projectDir, String dataDirectory, String rootNamespace, String language)
à Microsoft.EntityFrameworkCore.Tools.AppDomainOperationExecutor..ctor(String assembly, String startupAssembly, String projectDir, String dataDirectory, String rootNamespace, String language)
à Microsoft.EntityFrameworkCore.Tools.Commands.ProjectCommandBase.CreateExecutor()
à Microsoft.EntityFrameworkCore.Tools.Commands.MigrationsAddCommand.Execute()
à Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
à Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
Le format du chemin d'accès donné n'est pas pris en charge.
= The format of the given path is not supported.
Guy
There is something new... It occurs only once by following your suggestion...
Look at the path.... below (in red). It's a assembly /exe path problem...After ....bindebug, it restarts with the full path
PM> Add-migration -Name "CreateSchoolDB" -Context "SchoolContext" -Project "EFCTutorials" -debug -verbose
Using project ''.
Using startup project ''.
Build started...
Build succeeded.
E:Visual Studio 2017X Sharp SolutionsEFCTutorialspackagesMicrosoft.EntityFrameworkCore.Tools.2.1.0toolsnet461anyef.exe migrations add CreateSchoolDB --json --context SchoolContext --verbose --no-color --prefix-output --assembly "E:Visual Studio 2017X Sharp SolutionsEFCTutorialsEFCTutorialsbinDebugE:Visual Studio 2017X Sharp SolutionsEFCTutorialsEFCTutorialsbinDebugEFCTutorials.exe" --startup-assembly "E:Visual Studio 2017X Sharp SolutionsEFCTutorialsEFCTutorialsbinDebugE:Visual Studio 2017X Sharp SolutionsEFCTutorialsEFCTutorialsbinDebugEFCTutorials.exe" --project-dir "E:Visual Studio 2017X Sharp SolutionsEFCTutorialsEFCTutorials" --language XSharp --working-dir "E:Visual Studio 2017X Sharp SolutionsEFCTutorials" --root-namespace EFCTutorials
System.NotSupportedException: Le format du chemin d'accès donné n'est pas pris en charge.
à System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)
à System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
à Microsoft.EntityFrameworkCore.Tools.OperationExecutorBase..ctor(String assembly, String startupAssembly, String projectDir, String dataDirectory, String rootNamespace, String language)
à Microsoft.EntityFrameworkCore.Tools.AppDomainOperationExecutor..ctor(String assembly, String startupAssembly, String projectDir, String dataDirectory, String rootNamespace, String language)
à Microsoft.EntityFrameworkCore.Tools.Commands.ProjectCommandBase.CreateExecutor()
à Microsoft.EntityFrameworkCore.Tools.Commands.MigrationsAddCommand.Execute()
à Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
à Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
Le format du chemin d'accès donné n'est pas pris en charge.
= The format of the given path is not supported.
Guy