1

Firstly, if anyone knows the book Professional ASP.NET MVC5 I'm referring to page 87 but in general it's referencing the MvcMusicStore tutorial - scaffolding a store manager section.

Is there a reason we create a new db context instead of using the existing ApplicationDbContext?

I want to stamp any changes to an album with a userID so added the following to the Album class.

public virtual ApplicationUser SubmittedBy { get; set; }

public virtual ApplicationUser ModifiedBy { get; set; }

but when I try to add a controler as per p87 in the book I get the below error, even after cleaning, building and rebuilding the project.

I also added the following to ApplicationUser class to try to resolve the issue but no joy

[Key]
public virtual int ApplicationUserId { get; set; }

Could the issue be that the IdentityModels with their own DbContext are in the same folder as the rest of my models?

There was an error running the selected code generator:

'Unable to retrieve metadata for 'MvcMusicStorePrototype.Models.Album'.

One or more validation errors were detected during model generation:

IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType.

IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType.

IdentityUserLogins: EntityType: EntitySet 'IdentityUserLogins' is based on type 'IdentityUserLogin' that has no keys defined.

IdentityUserRoles: EntityType: EntitySet 'IdentityUserRoles' is based on type 'IdentityUserRole' that has no keys defined.

Installed package versions are as follow:

Id Version
Description/Release Notes

-- ------- ------------------------- Antlr 3.4.1.9004 ANother Tool for Language Recognition, is a language tool that provides a framework for constructing recognizers, in... bootstrap 3.0.0
Sleek, intuitive, and powerful front-end framework for faster and easier web development. EntityFramework 6.1.1 Entity Framework is Microsoft's recommended data access technology for new applications.
jQuery 1.10.2 jQuery is a new kind of JavaScript Library....
jQuery.Validation 1.11.1 This jQuery plugin makes simple clientside form validation trivial, while offering lots of option for customization.... Microsoft.AspNet.Identity.Core 2.1.0
Core interfaces for ASP.NET Identity.
Microsoft.AspNet.Identity.E... 2.1.0 ASP.NET Identity providers that use Entity Framework.
Microsoft.AspNet.Identity.Owin 2.1.0 Owin implementation for ASP.NET Identity.
Microsoft.AspNet.Mvc 5.2.0 This package contains the runtime assemblies for ASP.NET MVC. ASP.NET MVC gives you a powerful, patterns-based way t... Microsoft.AspNet.Razor
3.2.0 This package contains the runtime assemblies for ASP.NET Web Pages. ASP.NET Web Pages and the new Razor syntax provi... Microsoft.AspNet.Web.Optimi... 1.1.3 ASP.NET Optimization introduces a way to bundle and optimize CSS and JavaScript files.
Microsoft.AspNet.WebPages 3.2.0 This package contains core runtime assemblies shared between ASP.NET MVC and ASP.NET Web Pages.
Microsoft.jQuery.Unobtrusiv... 3.2.0 jQuery plugin that unobtrusively sets up jQuery.Validation.
Microsoft.Owin 2.1.0 Provides a set of helper types and abstractions for simplifying the creation of OWIN components. Microsoft.Owin.Host.SystemWeb 2.1.0 OWIN server that enables OWIN-based applications to run on IIS using the ASP.NET request pipeline.
Microsoft.Owin.Security 2.1.0 Common types which are shared by the various authentication middleware components.
Microsoft.Owin.Security.Coo... 2.1.0 Middleware that enables an application to use cookie based authentication, similar to ASP.NET's forms authentication. Microsoft.Owin.Security.Fac... 2.1.0 Middleware that enables an application to support Facebook's OAuth 2.0 authentication workflow.
Microsoft.Owin.Security.Google 2.1.0 Contains middlewares to support Google's OpenId and OAuth 2.0 authentication workflows.
Microsoft.Owin.Security.Mic... 2.1.0 Middleware that enables an application to support the Microsoft Account authentication workflow. Microsoft.Owin.Security.OAuth 2.1.0 Middleware that enables an application to support any standard OAuth 2.0 authentication workflow. Microsoft.Owin.Security.Twi... 2.1.0 Middleware that enables an application to support Twitter's OAuth 2.0 authentication workflow. Microsoft.Web.Infrastructure
1.0.0.0 This package contains the Microsoft.Web.Infrastructure assembly that lets you dynamically register HTTP modules at r... Modernizr 2.6.2
Modernizr adds classes to the element which allow you to target specific browser functionality in your styles... Newtonsoft.Json
6.0.3 Json.NET is a popular high-performance JSON framework for .NET
Owin 1.0 OWIN IAppBuilder startup interface
Respond 1.2.0 The goal of this script is to provide a fast and lightweight (3kb minified / 1kb gzipped) script to enable responsiv... WebGrease
1.5.2 Web Grease is a suite of tools for optimizing javascript, css files and images.

11
  • are you sure that the code in the book is using Microsoft.Asp.NET Identity 2.0? It's drastically different from Identity 1.0 or SimpleAuthentication.
    – Claies
    Commented Mar 16, 2015 at 19:28
  • @Claies the book is using OAuth so I guess that's Identity 2.0?
    – rory
    Commented Mar 16, 2015 at 19:45
  • not necessarily. OAuth is a pattern, Identity is a set of classes that implement the pattern. You can do OAuth without Identity, or with Identity 1.0....
    – Claies
    Commented Mar 16, 2015 at 19:51
  • put it another way; did the instructions in the book tell you to select an authentication option when you created the project?
    – Claies
    Commented Mar 16, 2015 at 19:52
  • I'm opening the sample code for the book now, to look at what it is using.
    – Claies
    Commented Mar 16, 2015 at 19:55

1 Answer 1

0

Ok, so Application User's Id is a string. I followed this article in order to convert the Id type to int and then created Id's for the users.

A lot of work just to change the id data type from string to int but there we go. I could have just used strings I guess but I'd rather all my key data types be the same.

Not the answer you're looking for? Browse other questions tagged or ask your own question.