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

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.

Related

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

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.

trouble scaffolding entity framework based controller in ASP.Net Core 2.0

I'm using Visual Studio 2017, v15.3.1 and am trying to follow a tutorial about creating some WebAPI endpoints with Entity Framework, as outlined here
In my case I'm using the good old Northwind SQL database instead of the author's blogging example, which I don't think should be an issue?
At any rate, when I get to the bit where I'm supposed to create a controller, I right-click the controllers folder in my solution, select 'API Controller with actions, using Entity Framework' and choose my EF model class (Orders, Employees, it doesn't seem to matter) and the Data Context which I generated successfully earlier in the tutorial.
When I select Add there's an attempt to scaffold, but I'm then told in a popup: There was an error running the selected code generator: 'No parameterless constructor defined for this object'.
I've looked at this error message online and others have had similar problems, but nothing they tried quite matches my scenario, and their solutions haven't fixed this issue.
My generated EF model classes do have parameterless constructors defined, so I'm not sure what the error is referring to?

Trying to upgrade, from EF4.1 to EF6.1, ObjectContext reference code?

I am trying to upgrade my MVC3/.NET4.5 application to use EF6.1, in the main part for its performance improvements.
One of my problem code lines is :
private AppEntities db = new AppEntities();
I have removed system.data.entity from references and web.config, but this line still seems to be looking for this dll. I did try and add:
using System.Data.Entity.Core.Objects.ObjectContext;
Did not seem to fix the issue with AppEntities line trying to find system.data.Entity v4.0.0.0
Many thanks
EDIT:
I managed to sort this by adding:
using System.Data.Entity.Core.EntityClient;
using System.Data.Entity.Core.Objects;
to AppEntities.cs file.
Also needed to add to some of the POCO files.
using System.Data.EntityClient;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
It all builds fine.
However my problem now is that it seems to take an age to show the page on first load, guess this is to do with native code creation. Also I have heard that much EF code that was native in .NET is now MSIL in Entity Framework.dll and thus need compiling to native code as well. Perhaps this is what is causing my pain, see: EF6 Warm up metrics

Visual Studio Entity-Framework-Designer: Update model from database broken by custom provider

We have decorated the default Entity Framework provider to support custom ExpressionsVisitors. So far everything works out the way we intend it to be.
After adding the custom provider entry into the machine.config and placing the Custom Provider Assembly in the machine’s GAC the entity framework designer was not broken any more and did show up correctly.
However the command “Update model from database...” just ends in a message box stating that:
An exception of type 'Microsoft.VSDesigner.Data.Local.ConnectionStringConverterServiceException' occurred while attempting to update from the database. The exception message is: ''.
We’re using VS Premium 2012 with .net 4.5.
Where does this error come from and what needs to be done to fix it?
Any Help or Advice Gladly Appreciated

Entity Framework: Unable to load one or more of the requested types

I am getting a specific exception that I am confused about. I recently changed the target framework of my application from .net Framework 4.0 client profile to .net Framework 4.5. That has apparently caused my entity framework to go a little haywire. I get this exception when I run my application...
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the
LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at System.Data.EntityUtil.GetTypesSpecial(Assembly assembly)
at System.Data.Metadata.Edm.ObjectItemAttributeAssemblyLoader.LoadTypesFromAssembly()
at System.Data.Metadata.Edm.ObjectItemAssemblyLoader.Load()
at System.Data.Metadata.Edm.ObjectItemAttributeAssemblyLoader.Load()
at System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, ObjectItemLoadingSessionData loadingData)
The thing is it used to work before I made this change... What did I manage to mess up? Do I need to regenerate these entities? How do I go about trouble shooting and fixing this problem? Thanks.
Two ways to debug this:
Run your program in the debugger, turn on break-on-unhandled exceptions and then inspect the LoaderExceptions property of the exception like the message says. That should give you an idea of which type is not loading.
Run fuslogvw.exe and inspect the failure that is logged there. If an assembly was not found or could not be loaded, it will tell you which one and possibly why.