I have the following model in my application, but when I try to generate a view on the controller using it I get the error "Unable to retrieve metadata for Jop_Offers_Website.Models.JobRequest":
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using WebApplication3.Models;
namespace Jop_Offers_Website.Models
{
public class JobRequest
{
public int Id { get; set; }
public string Message { get; set; }
public DateTime ApplyDate { get; set; }
public int JobId { get; set; }
public string UserId { get; set; }
public virtual Jobs job { get; set; }
public virtual ApplicationUser user { get; set; }
}
}
When I use other models to add view, or if I comment out the job
and user
properties the view is generated successfully.
The Jobs
Model:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace Jop_Offers_Website.Models
{
public class Jobs
{
//id to be primary key of Jobs table
public int Id { get; set; }
//job title
[Required]
[Display (Name ="أسم الوظيفة")]
public string JobTitle { get; set; }
//job description
[Required]
[Display(Name ="وصف الوظيفة ")]
public string JobDescription { get; set; }
//jop image
[Display(Name ="صورة الوظيفة ")]
public string JobImage { get; set; }
//id of categories to relate to Job category Type 1 to many relationship
//[Required]
public int CategoryId { get; set; }
//object of category to detect job category
public virtual categories category { get; set; }
}
}
The ApplicationUser
model:
using System.Data.Entity;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
namespace WebApplication3.Models
{
// You can add profile data for the user by adding more properties to your ApplicationUser class, please visit https://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
public class ApplicationUser : IdentityUser
{
public string UserType { get; set; }
public string Neabouring { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("JobConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
public System.Data.Entity.DbSet<Jop_Offers_Website.Models.categories> categories { get; set; }
public System.Data.Entity.DbSet<Jop_Offers_Website.Models.Jobs> Jobs { get; set; }
public System.Data.Entity.DbSet<Jop_Offers_Website.Models.RoleViewModel> RoleViewModels { get; set; }
public System.Data.Entity.DbSet<Jop_Offers_Website.Models.JobRequest> JobRequests { get; set; }
}
}
Any model used to add views but I can't add the view by using JobRequest
Model
and when I use JobRequest
model without ApplicationDbContext
the view is generated successfully .