Database entity model was generated with warnings or errors (asp.net)

Got some errors when trying to generate a DB entity model for a ASP.net MVC website. The error message was “The model was generated with warnings or errors. Please see the Error List for more details. These issues must be fixed before running your application”.

This turned to be caused by some tables that was lacking a primary key. Once a primary key was set on these tables the model could be generated successfully.

Entity type is not part of the model for current context

The entity type <Type> is not part of the model for the current context.

ExceptionType:
System.InvalidOperationException
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
vid System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
vid System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
vid System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
vid System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
vid System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
vid System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()

Cause:
Wrong meta data in the MVC entity framework connection string. Had multiple entity models to seperate databases in the project. But had copied the connection strings to the other databases and changed the database settings and credentials. But forgot to update the entity model names in the meta data section of the connectionstring.

Solution:
Update database model names in the connection strings.

Local IIS failed to map the path ‘/’

Got an exception of System.InvalidOperationException: “Failed to map the path ‘/'” when starting the site on a local IIS.

System.Web.HttpRuntime.HostingInit(HostingEnvironmentFlags hostingFlags, PolicyLevel policyLevel, Exception appDomainCreationException) +556

[HttpException (0x80004005): Det gick inte att mappa sökvägen /.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +579
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +118
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +730

——
With my modest knowledge about hosting a site on a local IIS the solution turned out to be really simple.

1. Start a new command prompt in administrator mode.
2. Run command: “iisreset”

TADA!

Call stored procedure via DBContext

Tried to call a SP via Entity framework (DBContext) but got a exception that parameter is not supplied.

My call looked like:
context.Database.ExecuteSqlCommand(“NameOfSP”, new SqlParameter(“@param1”, 1), new SqlParameter(“@param2”, DateTime.Now), new SqlParameter(“@param3”, “test”));

The right call should look like:
context.Database.ExecuteSqlCommand(“NameOfSP @p1, @p2, @p3”, new SqlParameter(“@p1”, 1), new SqlParameter(“@p2”, DateTime.Now), new SqlParameter(“@p3”, “test”));

You should include the parameter name after the name of the stored procedure.