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

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?

Related

add scaffolded item wizard cannot resolve data model class

everyone.
I'm trying to create new Scaffolded item for simple ASP.NET Wep API application which should be based on domain object class and DbContext derivative in separate assembly. The assembly is in the solution, target app has a reference to it (and manually created code which invokes the classes from my lib is build up without any errors) and, obviously, the classes I've mentioned have access modifier public.
The problem is wizard for creating new scaffolded item cannot see my model classes. (By the way, when the model classes were in another ASP.NET MVC5 app the wizard worked well.) I'm using Visual Studio 2013 Update5.
How to fix this? Any workaround would be helpful too!
Sorry for disturbing.
the origin of the problem seems to be that I've move my data model classes from ASP.NET MVC app into my class library in wrong way.
I've not just cut/paste them, but copy-paste, cut-paste (confirmed replacement).
this is the only thing which could cause the problem (although I still don't know the details).
Never the less I've started from the beginning again and cut/past the data model files initially - everything seems to work fine now.

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 disable code-first feature in EF (MVC4 Visual Studio 2012)

How to disable code-first feature in EF (Visual Studio 2012)
I am using Visual Studio 2012, MVC4 (Internet application template).
I want to use EF, but not with its code-first feature. I would want the application to error out, rather than create or modify my database based on my code. (i just can not live with this feeling of my database being changed behind the scenes ... i want the application to use the exact db i have created ... and if there is any thing that has to be changed, i'll do it my self)
is this possible with the new Ef (VS2012)?
i have seen many people asking this, but so far i am unable to find the answer.
You can use Code First and ensure that your database never gets updated or overwritten when you change your model by setting the database initializer to null:
Database.SetInitializer<MyDbContext>(null);
It's a static method of the Database class and should be called at the beginning of your application, for example in global.asax or in a static constructor of your context class. Doing this you have to change model class and database schema manually so that they match.
You can also use the Reverse Engineer feature to create a Code First model from an existing database. It is explained here: http://msdn.microsoft.com/en-us/data/jj200620
Or if you don't want to use Code First at all and work with a model designer you can use the Database First approach, explained here: http://msdn.microsoft.com/en-us/data/jj206878
An overview about all the possible options is here: http://msdn.microsoft.com/en-us/data/ee712907.aspx

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

Ria Services Wizard with referenced Entity model problem?

Imagine this structure. A solution with the following projects
/Backend (RIA Silverlight client)
/Backend.Web (RIA Silverlight Host /
Service)
/Core (Utility includes)
/Frontend.Web (Front line MVC app)
A entity framework model built in /Core should be able to be seen in Backend.Web IF there is a reference. Which there is. Now, when the Domain Service creation wizard shows up, it is happy to find the Entity model, but it will not enable the "Generate associated classes for metadata" option.
The only solution seems to be putting the Edmx file into /Backend.Web - but that seems ugly to me :)
Thanks!
It woudl appear that this scenario is better handled with a "RIAServicesLibrary" as mentioned by #brada in his blog post on the topic.