Error: The model backing the 'NameDbContext' context has changed since the database was created - entity-framework

The original issue I was trying to solve was related to this error message. This is happening in a Web API 2 Project running on Azure.
Error 1
Introducing FOREIGN KEY constraint 'FK_dbo.Merchant_MerchantId' on table 'Keys' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION,or modify other FOREIGN KEY constraints.
The FOREGIN KEY error message was only introduced after I tried to upload a release build of my API to my Azure App Service. I recently upgrade to version 15.9.11 of Visual Studio 2017, but I have no idea if that is the cause of the FOREIGN KEY issue that started this mess. This API and database has been running for years with no problems whatsoever.
To try and fix the problem, I added the following line to my OnModelCreating(DbModelBuilder modelBuilder) method.
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
Adding the line kind of fixed the issue and Error 1 has gone away, but now the API is not finding records that are actually in the database. I'm not sure why that is.
I have since commented out the line and uploaded a new build of my App Service. I'm now getting this error message.
Error 2
Error: The model backing the 'NameDbContext' context has changed since the database was created.
At this stage, I'm causing more problems instead of fixing my original problem.
Any help to recover from this mess is much appreciated! Thanks!
UPDATE 1
I worked with a Microsoft Engineer on the "The model backing the 'NameDbContext' context has changed since the database was created" error. I added the following to the Application_Start() in the Global.asax.cs file. Adding this did not delete or alter any of my data in SQL. Error message 2 has gone away. The API is still not returning records that are in the database, so I still have a problem to fix.
Database.SetInitializer<FaceOffersDbContext>(null);
UPDATE 2
I ran my API locally with no problems. This means that the problem is only happening in Azure. I'm working with Microsoft to narrow down the issue and come up with a fix.

It seems your database schema is changed and not at per with your entity framework, You may try to forcefully update your database using package manager console.

Related

Error while scaffolding Identity: Two Versions of Microsoft.AspNetCore.Identity?

I'm attempting to add scaffolding for Identity in a blazor server app. When I do I get the error below (it's repeated about 25 times, I just capped the first two for brevity).
This is confusing me because it is stating there are two versions of AspNetCore.Identity, 6.0.0.0 and 2.2.0.0, both with the same PublicKeyToken.
Does anyone have any idea what's going on here?
I had some problems and i fixed them. Try to update all Nuged packages and delete identity pages and controllers then create again.

Opshub migration failures

I'm migrating a large amount of projects from a on premise tfs2010 to vso, nearly all of them was able to migrate without any problems, but a few are creating errors. I am using Opshub Integration Manager Framework-OVSMU-V1.2.0.000.
1.
OH-TFS-Connector-0054: Test Step Id cannot be empty and It must be a valid number. Please check the Mapping and add valid mapping for the Test Step Id.
The most common error. This error is also described in opshub-visual-studio-online-migration-utility-test-cases-failing, but has yet to receive an accepted answer. As mentioned in this post the cause if the problem might be Shared Steps, so I tried removing one from a test case, and that made it pass in the migration utility. Unfortunately I need those test cases and it is not feasible for me to just delete them.
2.
OH-TFS-Connector-0051: Operation failed getCollectionMetaData. Server Error : TF201063: Adding a Test Case link to work item 18374 would result in a circular relationship. To create this link, evaluate the existing links, and remove one of the other links in the cycle.
After inspecting the Work Items that causes the error and concluding that there is no links, and no clear circular reference, not even a Shared Step linking to work item 18374. Upon further inspection I noticed that work item 18374 doesn't even exist.
Any help would be much appreciated.
OH-TFS-Connector-0054: Test Step Id cannot be empty and It must be a valid number. Please check the Mapping and add valid mapping for the Test Step Id.
This issue is addressed in latest release of OVSMU (1.3.0.000). You can download from
https://visualstudiogallery.msdn.microsoft.com/28a90a17-d00c-4660-b7ae-42d58315ccf2
OH-TFS-Connector-0051: Operation failed getCollectionMetaData. Server Error : TF201063: Adding a Test Case link to work item 18374 would result in a circular relationship.
This issue is scheduled for next release which will be out shortly. Check Visual Studio Gallery for further updates.
Thanks.

Error updating service reference

When trying to update a service reference in a class library (VS2013), i get the following error.
"The configuration for the service reference could not be updated due to the following issue: An error occurred creating the configuration section handler for system.serviceModel/bindings: AssemblyResolveEvent handlers cannot return Assemblies loaded for reflection only."
This same error happens when i try to delete the reference as well.
Any help in sorting would be greatly appreciated.
I've had the same issue after updating to VS2013 Update 2.
I've solved the issue by temporarily cutting the whole system.serviceModel section out of web.config, pasting it somewhere else like Notepad. Then, I've saved the web.config without the service model section. Then, I was able to update the service reference successfully. After updating the service reference, I've pasted the service model section back to web.config and it worked successfully.
I was able to work around this similarly to Can by temporarily removing the extensions element of the system.serviceModel section and any associated extension elements. In my case the extensions were Azure Service Bus extensions.
In my experience it has been as simple as to delete the service reference and re-adding it. For example, last time it happened it was on a WebService (not WCF, the old one), and the error started appearing after we changed one of the classes that was being sent as a return from different routines/functions. After adding one more property to the class, it started going crazy and prompting errors everywhere.
Just a simple Delete and re-Add Service Reference did the trick.
Only need to one time remove <system.serviceModel> section from web.config. After Create first service refrence , this section rebuild by Vs.

BreezeJS: Metadata() Error after upgrading Breeze 1.2 to 1.4 and EF 5.0 to 6.1

I tried to upgrade my project in Angular using Breeze 1.2, EF 5.0 to use latest Breeze/EF. The project was working fine, but I ran into various issues after upgrade.
Actually, I only need some new features in EF, so I tried to upgrade EF from 5.0 to 6.1 first. However, I can't install EF 6.1 with Breeze 1.2. So, I had to upgrade to Breeze 1.4 first. After that, I had to make some changes due to new namespaces to get the project compile again.
First problem is that route has changed. In v1.2, I used to call
var manager = new breeze.EntityManager("api/breeze");
but in v1.4, I had to call
var manager = new breeze.EntityManager("breeze/breeze");
Then, I got this error on client:
GET http://localhost:1476/breeze/breeze/Metadata 500 (Internal Server Error)
On server, I got this error message on call to get Metadata():
The property 'Id' cannot be configured as a navigation property. The
property must be a valid entity type and the property should have a
non-abstract getter and setter. For collection properties the type
must implement ICollection where T is a valid entity type.
I'm getting lost here. I found this post and this post mentioning the namespace changes. However, I have no idea how to fix it in my case. For example, on server, my EntityState is coming from Breeze.ContextProvider, not from System.Data.
What is problem? Are my entities (I have a lot!) no more valid? Do I have to redefine all my entities?
Any hint is much appreciated!
Okay, after much struggle, I got it work now, but with the same code, so I'm not sure how it got fixed. This are the steps I tried. I commented out all the entities first, then I get the metadata without problem. Then, I added back the entities one by one and run get metadata, but no more errors.
One possible guess is that, after upgrading to EF 6.1, I didn't change the entities, so the my db schema didn't change and EF 6.1 is incompatible with the previous schema. Once I changed the entity, the auto migration kicks in. It's just my guess.
Hope it helps in case somebody runs into the same problem.

How to debug 'no entities specified' when working with ZSync and CoreData Syncing

I'm trying to get ZSync to work between a desktop and iPhone app. I've got my schemas set up and all info matches between my MOM and my schema so I should be good to go. When I initiate my sync, however, I get this error.
|Miscellaneous|Error| SyncServices
precondition failure in [ISyncSession
_validateClient:entityNames:beforeDate:clientHasTruthForEntityNames:target:selector:]:
no entities specified
Anyone know what this means, and how to debug it?
I'm a novice with this SyncServices stuff.
Cheers!
Update
Ok, I've got it showing in syncrospector, but still getting the unrecognized error.
What do you mean by my clientdescription at the Daemon is wrong?
Thanks.
Update
Alright, I had the clientDescription working , but now when this fires:
ZAssert([[ISyncManager sharedManager]
registerSchemaWithBundlePath:path],
#"Failed to register sync schema");
I get this error :(
[NOTE: this exception originated in
the server.]
*** -[NSCFArray insertObject:atIndex:]: attempt to
insert nil
This is an issue in your Sync Services settings. It means that you have not declared what entities need to be synced. I suggest comparing your SyncSchema subproject (for your desktop app side) to the one included in the SampleDesktop project.
update
I checked all that, to no avail. I am using a versioned mom, would that make a difference? In my ManagedObjectModels, should I use the name of the version or the collection? (mom or momd?) Thanks, I'm almost there!
No, the schema should point to your latest model. Are you certain that it is pointing to it correctly? That can be one of the trickiest bits. Are you including the model in the schema bundle or are you making a reference to it?
update
First, please put these updates into your question, the comment section is really not meant for them.
Alright, got past this problem. Syncing starts now I get "failed to register client because: client named Xmac wants to sync unrecognized entity named: X.Entity" This happens with all my entities, sadly.
This error means that your sync schema is still not completely valid. Does your desktop client sync?
Can you see its data in the syncrospector?
If so then your clientdescription at the Daemon is wrong. If it doesn't sync then solve that first as it sounds like your SyncSchema bundle is still incorrect. I suggest trying to compare it against the sampleDesktop application that is included in the project.
update Syncrospector
Ok, I've got it showing in syncrospector, but still getting the unrecognized error. What do you mean by my clientdescription at the Daemon is wrong? Thanks.
In the syncrospector I am guessing that you are seeing all of your entities and data?
On the Daemon, there is a clientDescription.plist. This plist describes what data that the Daemon is going to sync with. That plist needs to be updated (since the default one refers to the sample app, etc.) to reference your data structures just like your desktop application does.
In the very near future, this piece will be moved to a plugin so that you are not modifying the daemon directly. Expect to see updates on the project itself during the next couple of weeks. But for now, (and will be reusable), modify the plist inside of the daemon and you should be ready to sync.
update ZAssert
That line unwinds into:
BOOL success = [[ISyncManager sharedManager] registerSchemaWithBundlePath:path];
NSAssert(success, #"Failed to register sync schema");
A few things can cause this:
Your path is nil, check that in the debugger
There is something wrong with your sync schema.
What other debug comments are you seeing?