0

I'm trying to create a relation in two models, Courses and Assignments:

namespace MyWebApp.Core.Models
{
public class Course
{
    [Key]
    public int Id { get; set; }

    [Required]
    [RegularExpression(@"[A-Za-z]{3}\d{3}", ErrorMessage="Invalid Course ID")]
    [Display(Name="Course ID")]
    public string CourseSeq { get; set; }

    [Required]
    [Display(Name = "Course")]
    public string CourseName { get; set; }

    [Required]
    [Display(Name = "Professor")]
    public string Professor { get; set; }

    public virtual ApplicationUser User { get; set; }
    }
}

namespace MyWebApp.Core.Models
{
public class Assignment
{
    public int Id { get; set; }

    [Display(Name="Assignment")]
    [Required]
    public string Name { get; set; }

    [Display(Name="Due on")]
    public DateTime DueDate { get; set; }

    [Display(Name="Description")]
    public string Description { get; set; }
    }
}

The UserApplication : IdentityUser (from Microsoft.AspNet.Identity) class is defined in IdentityModels which is created by default when choosing a MVC template. I've created another project in my solution (MyWebApp.Core) which will hold the Models. I'm getting an error when creating a prop (user ) which will relate the model to the user tables. Basically Assignments relates to Courses which relates to Users. For some reason I can add the using directive in the .Core project, it doesn't find it in references. I've also moved the default IdentityModels from MyApp.Web.Models to MyApp.Core.Models, which created a couple error due to missing references. Does it make sense to move the default IdentityModels to a class lib .core, and change it's namespace or is it better to keep the identity Models in .wed

Tieson T.
  • 20,774
  • 6
  • 77
  • 92
  • what's the problem so far ... ? do u have any compiling error ? – Sherif Ahmed Apr 11 '15 at 22:48
  • Well, once I move the IdentityModels to MyWebApp.Core, I get at least 17 errors, almost all having to do with missining refs/assemblies. Here is my repo, you can take a look at the way I have the solution set up. I reverted back to a previous working version where the IdentityModels is in .Web –  Apr 11 '15 at 22:53
  • https://github.com/lf-hernandez/MyAssignStore –  Apr 11 '15 at 22:53
  • From what I understand it's a good practice to place all your Models in a separate class file. And have the Views and Controllers in the actual web app. –  Apr 11 '15 at 22:55
  • ok if you moved you identity models to the Core project you will need to install 3 packages in the Core projected "EntityFramework", "Microsoft.AspNet.Identity.Core" and "Microsoft.AspNet.Identity.EntityFramework" and it will be fine ... – Sherif Ahmed Apr 11 '15 at 23:03
  • Yes. So, when I tried, I was able to add a reference to EF. But for some reason Microsoft.AspNet.Identity and MIcrosoft.AspNet.Identity.EF did not show up. The only refs I found were Microsoft.AspNet.Scafolding and M.AN.Scafolding.EF; ... I apologize about the abriviatiions –  Apr 11 '15 at 23:08
  • from tools >> NuGet Package Manager >> Package Manager Console ... and any package you need u can do that .... Install-Package PACKAGE_NAME -version VERSION HERE ...... -version is not mandatory but if you need a specific version u can get it like that – Sherif Ahmed Apr 11 '15 at 23:11
  • I actually have the package installed already, for some reference I can't add the ref to .Core( It is a Class Library not a ASP.NET MVC Web App) –  Apr 11 '15 at 23:17
  • I don't understand what u mean by "I can't add the ref to .Core" ? – Sherif Ahmed Apr 11 '15 at 23:20
  • So when you right click references -> Add Reference -> upper right corner search bar - > I enter Microsoft.AspNet.Identity and nothing shows up. I can't add those to references to .Core....but they are present in .Web as well as installed in the solution –  Apr 11 '15 at 23:25
  • 1
    you won't add reference to them like that ... open the Package Manager Console and write Install-Package Microsoft.AspNet.Identity.Core ... click ENTER. this will add the reference automatically. – Sherif Ahmed Apr 11 '15 at 23:28
  • I think you want this http://stackoverflow.com/questions/23446919/moving-asp-net-identity-model-to-class-library?rq=1 – Jasen Apr 12 '15 at 00:27
  • Please note that the tag [tag:model-view-controller] is intended for questions about the *pattern*. You've already tagged it with the relevant ASP.NET implementation, so you don't need to (and shouldn't) add the pattern tag. – Tieson T. Apr 12 '15 at 20:28

1 Answers1

0

Packages were installed only in .Web. The correct way to have added the references was by right click on the Solution -> Manage NuGet Packages -> Installed -> Click on Microsoft.AspNet.Identity, Microsoft.AspNet.Identity.EntityFramework [manage] and select .core project.