Why am I unable to add MVC controllers? - asp.net-mvc

I'm pretty new to MVC. I've built an EDMX, successfully created the models and am now trying to go through scaffolding to build a controller. The first thing I notice is that in the Model Class dropdown, I have duplicates:
Now, "BillysRentals2" is the name of the project. I don't know where those extras are coming from or where these "Model classes" are stored. It's true I've had to re-do the adding of the ADO.NET Entity thing several times, but even after I completely delete the EDMX and all its contents, some of those model classes still remain, so which are the real ones and where are the others hiding? It's confusing when you create "Model" and you're seeing "Model1" and stuff popping up.
But the second problem is that once I select a class, and press OK, I get this beautiful gem:
And yes, I tried removing the EDMX completely, doing a Re-build, removing and re-adding connections, Rebuilding again, and I'm still getting that message. What's wrong? I'm sure the fact that I'm getting multiple entries above means that there are bits and pieces of my previous efforts lying around someplace that are confusing MVC (not that it's hard to do) but how do I find them and get rid of them to start over?
And P.S. what is the difference anyway between a model class and a data context class?

I had several metadata files leftover from the last time, which had field names that I didn't import this time around.

Related

Is there a way to changing Core Data schema without migration during early development?

At the early stages of development, where data retention is no issue and experimental changes to the schema are expected to be numerous, is there a way to avoid migration? Namely, just to dump the database and start over each time.
Everything I try leads to the error: "The model used to open the store is incompatible with the one used to create the store".
Lightweight migration looks do-able, but I'll end up lots of unwanted versions and messy code. I'd also like to experiment with relationships (no wise cracks), but understand I'd need to commit to a heavyweight migration afterwards!
If the solution is to check for the existence of the original database using NSFileManager and delete/remove it if found, could someone please show the swift code with an example name of the original database, and how it can be effectively removed.
I've been trying several suggested solutions, such as dragging a copy of the .xcdatamodeld file onto the desktop, deleting the file in xcode and bringing it back in, but I keep getting the error that the model and store are not the same.
Answered in one line in first comment, but appreciated in reverse proportion.

`Unable to load the specified metadata resource` suddenly appears without code changes

PLEASE NOTE: None of the answers in the link above (which I don't seem to be able to remove) helped me. As I explain below, I had already tried all that stuff
I have a web site, developed in VS2013 using ASP.NET MVC5/WebAPI2, which has several related projects such as a service layer, repository layer, etc. Down at the bottom of the stack is a class library that holds an EF model. I have separated the actual entities into another class library, to allow them to be reused without requiring the model library.
All of this has been working fine. The web site was running, and I could make calls to the WebAPI methods as well.
I just uploaded the latest version to the production server, and all is working fine there. Then came back to VS to carry on work, and when I try to run up the web site, I get an exception
Unable to load the specified metadata resource
Searching around, it seems that the cure for this is to modify the connection string to point to the actual assembly name instead of using the default . I have two problems with this, first is that none of the config files in the solution have been touched today (by me at least, and the file history form source control confirms this), so there's no reason why it should suddenly stop working after being deployed, and second, even if I add the assembly name, I get the same exception.
Anyone any ideas what I can do? I'm completely stuffed now. Can't do anything.
Edit: I tried again to specify the assembly in the connection string, and now get the exception Unable to resolve assembly. I have checked the assembly name in a decompiler, and I'm pretty sure got it right.
Edit again: I just pulled the version that I deployed from source control, and that gives the same exception, so I'm sure this is nothing to do with any files I've changed (or even that have been changed by VS). The version on the production server is still working, but the source code that drives that exact same version gives the exception. So, I'm certain that the answer is NOT to be found in the myriad other versions of this question, but is somewhere else.
Found the problem, and am posting it here in the hope that it will help someone else, as I don't think this was clear in any of the other posts on this issue.
I have a layered solution, with the web project referencing a service layer, which references a repository layer which in turn references the model project. It seems to for EF to work, whichever layer actually causes the database to be accessed requires a reference to the model project. My service layer project, which was where ToList() was being called (thus enumerating the query, and causing the database to be hit) didn't have a reference to the model project, so was failing to load the assembly.
I didn't need to alter the metadata part of the connection string either, as once the service layer had a reference to the model project, it was able to find the resources by itself. Having said that, one thing I did learn from all of this is that you can speed up the creation of the model (slightly) by specifying the assembly containing the resources explicitly, as this saves the framework having to search through all loaded assemblies to find them. I'm not sure if this will make any noticeable difference, but it can't harm.
I still can't explain how this had been working up until now, and suddenly stopped, as I hadn't changed any references, nor the way I was doing the data access. Still, it seems to be working now, which is all that matters.
Hope this helps someone.

MVC3 Entity Connection string disappearing

I am having a very frustrating problem with my current project. It is continually losing the connection string binding for Entity models.
I have multiple models for different databases in separate areas and was having no problems. Suddenly now whenever I try to update from the database I get the connection string setup prompt. I select for it to add it to the Web.config with the password but it doesn't ever pick it up there again. They all are still in the web config but it just doesn't see them.
If I remove all the connection strings from the config file it will write the new one there. Then when I try to set up a Stored procedure/Function Import, I still get the statement in the lower box:
No database connection has been configured for this model.
I have tried rebuilding the project and creating the models again from scratch and that works for a while. When I try and bring the project in under Perforce source control, it winds up getting re-corrupted & the connection string goes away. It affects all of my models too.
I am also using EF 4.x DbContext Generator to create context files. They work fine. I am also able to run the application and it connects to the database just fine and returns data. No issues there. I am just unable to update Entity Complex types from the DB or import any more stored procedures.
An even weirder occurrence was that I opened a broken project from a different directory then opened an uncorrupted copy it instantly became broken also. Contagious!
Any thoughts on where to look into to see why this is happening? Has anyone else had this issue?
I seem to have found where the issue is coming from.
I seem to have a bad value somewhere in my web.config which causes the issue. Here is the work around I found did the trick and showed it's the config:
When the binding breaks, I closed the project then swapped out the web.config with one from a good build which was missing a couple keys but worked well enough to bind.
I reopen the the solution and the "No database connection..." error goes away.
Then while the solution is still open I re-swap the web.config back in and it still works.
This is far from optimal but I can work until I figure out the bad value via doing some compares.
I will comment on this again once I determine the exact issue.

in orchard why does manually adding entries to the database not work?

I am using the Advanced Menu for Orchard, I have alot of duplicated content to add to multiple menus so was trying to do this directly into the database.
The problem I had was when I add items to the database the items don't show up and the CMS breaks and doesn't allow items to be added (this causes a duplicate primary key error).
Can anyone tell me why this is, and what I would need to do if I wanted to add entries manually?
Not knowing how you've tried to add them, it's hard to say. Maybe you've created part records without content item records, making them orphans? But again, I'm just guessing, as I have no idea what you tried to do.
For manual entries you might be better off using the command line utility. see http://www.orchardproject.net/docs/Using-the-command-line-interface.ashx
Or the import/export functionality (which I think just runs the command line stuff)
If yo want to know more follow piotr's blog. It's full of great stuff!
http://www.szmyd.com.pl/

ASP.NET MVC - Intellisense doesn't update model

Firstly, I've done a build, I've done a clean, I've done a rebuild, of both the project and the solution, so that's not the problem.
When I change my model for some reason the intellisense (in fact, it's not just the intellisense as if I do a build it comes up with an error as well) doesn't work. I have a model under ViewData.Model.ContractCostCentre which exists. VS isn't picking this up, at all. Instead, it's referring to an old one which has since been deleted and replaced with the prior one, this is called ViewData.Model.ContractCCList. So in my view I'm having to iterate over a ViewData.Model.ContractCCList despite this not even existing in my *.dbml file.
This isn't the first time I've had this problem, it seems to happen quite often if I change my dbml file (and it's likely to change as we work on highly progressive systems which are always subject to change).
Any ideas?
can you look into your ????.designer.vb or .cs, depend which language you are using
if you don't see that file, show all file in solution
intellisense is using that file
Kezzer,
At the top of your View, there is part of a line of code that determines what model type the page uses. It should look something like this (my example is in c#):
Inherits="System.Web.Mvc.ViewPage<ViewData.Model.ContractCCList>"
Change it to look like this:
Inherits="System.Web.Mvc.ViewPage<ViewData.Model.ContractCostCentre>"

Resources