I am not able to add migrations in visual studio 2022 , dot net core based project I am seeing the below error and I have tried different methods - frameworks

I am running a migration script using package manager console after setting dependencies in corresponding files in dot net core based project and i am receiving below error after running the below migration command in package manager console ,
Add-Migration "InitialCreate"
Error received :
Unable to create an object of type 'PaymentDetailContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
I have gone through different ways to troubleshoot this issue inorder to create a migration file
I am logging using windows authentication method and kindly help me to resolve this issue in visual studio 2022
Entity framework Dot Net Core Error In Adding Migrations
I have tried to check all the corresponding files whether any spelling mistakes in connection string file , added corresponding packages using browse option and installed
I am expecting this error to be resolved (below one ) after executing the script
Add-Migration "InitialCreate"
Unable to create an object of type 'PaymentDetailContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
and thereby generating the migration script inside web api project

Related

Entity Framework 6 .net Framework Migrations / Package Management Console - How Do You Run These In An Azure Pipeline?

I am setting up an Azure Release Pipeline and I need to execute any pending DB Migrations as part of the release.
I have been scouring the internet for over an hour and everything I can find is about dotnet Core, while the database is EF6 on .Net Framework, not dotnet Core (I've done this several times before for Core).
The problem, as I see it, is that EF6 works using Visual Studio's built in Package Manager Console - This just doesn't exist in an Azure Pipeline; It's a Visual Studio weirdness.
There seems to be several ways I can skin this cat, in my head, but I can't figure out how to start with either of them within the context of the pipeline...
OPTION 1: Run the Migrations on the Pipeline - but... how?
OPTION 2: SQL Scripts - Requires running the Package Manager to generate them so they can be run (if I could do that on the pipeline then I'd just run it anyway so these would have to be created locally and committed with the code which is somewhat backward as a solution IMO)
OPTION 3: Write a console app - Do I really have to do this??
You can try Entity Framework Migration Extensions.
This task allows a Build / Release to provide database connection parameters and execute an Entity Framework 6 migration against the database.
Build your project to an output folder and include the migrate.exe executable that comes with Entity Framework 6.
Create an automated build that packages up your files and makes them accessible during a Release.
Create a Release definition for the relevant Build
Add an EF6 Migration task. Once that task is added to an environment within the release, you'll need to enter the appropriate parameters to configure it. All file path parameters should be within the file system for the build, none of them are for TFS source control paths.
You can also check this article.
The answer here is to use the ef6.exe command line tool and make sure it gets shipped with your build.
This could be useful to anyone here until Microsoft update the non-existent docs: http://github.com/dotnet/EntityFramework.Docs/issues/1740 - This contains a table with a kind of translation matrix between the two.

The Type spatial_geometry is not qualified with a namespace or alias. Only primitive types can be used without qualification

We've got an existing solution that uses EF5 and DevArt's dotConnect for PostgreSQL to connect to a PostgreSQL 9.4 database, and generate the entities.
I just installed Visual Studio 2013, and the dotConnect for PostgreSQL provider, and pulled the repository. My colleagues have the same setup, which works on their machines.
When I tried to make a build, I got the error message described in the title. I have to open the .edmx file in XML view (because VS can't show the diagram since it contains errors), and every line containing spatial_geometry as type has blue squiggly lines:
When I remove the offending lines, the project builds, but then I'm missing the spatial geometry properties, which are kinda essential to the application. I can even regenerate the entities from the database, but then I get errors that the name is not valid for each of those same properties, and the properties are then simply missing.
Why does Visual Studio complain about that spatial_geometry type (and why does it do so on my machine but not on others')? Where does the conversion between spatial_geomerty and System.Data.Spatial.DbGeometry take place?
Try upgrading to the newest (7.11.1190) build of dotConnect for PostgreSQL. Does this fix the issue? If you do not have access to the licensed v7.11.1190, please check the same with a trial.

How can I run an Entity Framework 7 migration on a remote database using Powershell?

In a standalone entity framework 7 project (note, not a MVC project with an entity context where the command DNX might be used), how can I run a migration on a remote database using Powershell?
I am currently using Entity Framework 7.0.0-rc1-final with Visual Studio 2015 (14.0.23107.0).
At the moment there is no way you can use pure PowerShell to do this because a utility like migrate.exe does not exist yet and importing the EF PS modules is not possible as they require a Package Manager PowerShell Host.
Here are some ideas how you can update a remote db in EF7:
One thing you could do is use the package manager console commands from within VS as usual to update the remote db. You can create a second context that has the remote db connection string and use the update-database command specifying the context to use. These commands require the following package in EF7:
https://www.nuget.org/packages/EntityFramework.Commands/.
I have done this successfully in a class lib project.
Another solution would be to use DNX commands by creating a DNX project instead of a classic one. DNX projects are not just for web sites, it is just another type of project. Here is a link that shows how to create a console app DNX project:
http://docs.asp.net/en/latest/dnx/console.html.
So with this type of project you can use the provided DNX commands that you seem to be aware of.
I hope this helped. Maybe we can give more help if you describe your situation and your end goal in more detail.
Answer too long as a comment, so adding it here...
Have you looked at this article and the links in the answer?
From that answer
The problem with importing the module into a PowerShell console is that I believe the module expects to run in a context where it has a Visual Studio DTE object available. That environment is the NuGet Package Manager Console. This issue has been brought up before. Check out this blog post and this SO question.
This blog post shows how to write code that does migrations.
What might be helpful for readers of this question is what you have tried, what is not working, and other information that might help solve your problem.

UnintentionalCodeFirstException thrown by mstest

I have a test project which references another project, which in turn references a third project containing my Entity Framework 5.0 file (edmx). I find that I can run database-driven unit tests directly from Visual Studio, but when I run from mstest I get the following errors:
System.Data.Entity.Infrastructure.UnintentionalCodeFirstException:
Code generated using the T4 templates for Database First and Model
First development may not work correctly if used in Code First mode.
To continue using Database First or Model First ensure that the Entity
Framework connection string is specified in the config file of
executing application.
I have non-database connecting unit tests which run fine. I've fiddled with my various app.config EF connection strings and they seem to be OK (every tests runs fine on Visual Studio). The problem is when I run mstest from a command line on my desktop or on a build server. This is the command I use:
MSTest.exe /nologo /searchpathroot:"\Binaries"
/resultsfileroot:"\TestResults"
/testcontainer:"\Binaries\driver.orderedtest"
/testcontainer:"\Binaries\EF.DataAccess.dll"
/publish:"http://"
/publishbuild:"vstfs:///Build/Build/99" /teamproject:"ProjectName"
/platform:"Any CPU" /flavor:"Debug" /noisolation /detail:errormessage
/detail:errorstacktrace /detail:stderr
I have references to all dll's in the test project, as outlined here: Entity Framework custom tool does not correctly embed or load the model as resource files
I've been on this for a few days off and on, and it looks to me that this is an EF 5.0 bug, but according to the connect link this should be fixed, but it doesn't seem to be the case.

Entity Framework 4 CTP 5 Code First Development

I am trying to do some tests using EF4 + CTP5 with code first development by writing POCO classes and have faced the following problems
Connecting to existing database throws me the exception:
Model compatibility cannot be checked because the database does not contain model metadata
While I can create a new database from code by giving a new file name in a connection string, not able to open the file (database) using the Management Studio after running few tests against, the Management studio doesn't allow to add the file when trying to attach the database with no specific error detail provided.
For #1, did you try adding the following to your global.asax?
Database.SetInitializer<CustomContextNameHere>(null);
where "CustomContextNameHere" is your context object.
As far as #2 goes, I am assuming you mean the default ASPNETDB.MDF file. Have you tried opening the file with the Server Explorer in VS? It may open right up if you double-click on it in the solution.