Alors maintenant mes IdentityModels.cs ressemble à ceci:MVC 5 Code ajoutant d'abord nouvelle table de base de données avec UserId
using System;
using System.Data.Entity;
using System.Security.Claims;
using System.Security.Policy;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using System.Collections.Generic;
using System.Web.Mvc;
using System.Linq;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Leepio.Models
{
// You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
public class ApplicationUser : IdentityUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string City { get; set; }
//company
[Display(Name = "Virkshomedsnavn")]
public string CompanyName { get; set; }
public string ZipCode { get; set; }
//company
public int NrEmployees { get; set; }
//company
public string WorkField { get; set; }
public string Language { get; set; }
//Student
public string University { get; set; }
public string StudyProgramme { get; set; }
public int Semester { get; set; }
public string GraduationDate { get; set; }
//
[AllowHtml]
public string Description { get; set; }
//Student
public string Skills { get; set; }
public string Website { get; set; }
public string Address { get; set; }
//Student
[DataType("date")]
public DateTime DateOfBirth { get; set; }
public virtual ICollection<Blog> Blogs { get; set; }
public virtual ICollection<Application> Applications { get; set; }
public virtual ICollection<Project> Project { get; set; }
public virtual IList<Experience> Experience { get; set; }
public virtual ICollection<Skill> Skill { get; set; }
public virtual IList<Education> Education { get; set; }
public virtual IEnumerable<Experience> ExperienceOrdered { get { return Experience.OrderByDescending(e => e.EndYear); } }
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("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
public System.Data.Entity.DbSet<Leepio.Models.Project> Projects { get; set; }
public System.Data.Entity.DbSet<Leepio.Models.NewsletterMails> NewsletterMails { get; set; }
public System.Data.Entity.DbSet<Skill> Skill { get; set; }
public System.Data.Entity.DbSet<Leepio.Models.Application> Applications { get; set; }
public System.Data.Entity.DbSet<Leepio.Models.Contract> Contracts { get; set; }
public System.Data.Entity.DbSet<Leepio.Models.Experience> Experience { get; set; }
public System.Data.Entity.DbSet<Leepio.Models.Blog> Blogs { get; set; }
public DbSet<Category> Categories { get; set; }
public DbSet<Education> Educations { get; set; }
}
}
Ce que je veux faire est, par le code (migrations), ajouter une nouvelle table comme extensions de la table des utilisateurs (AspNetUsers) à travers le code quand j'inscris un nouvel utilisateur avec des données prises sur facebook, les données dont je n'ai pas besoin pour le tableau principal des utilisateurs peuvent aller à la seconde, appelons ça "FBData" "avec l'ID utilisateur approprié. Pour le mettre en perspective: L'utilisateur Register ajouterait userID, Prénom, Nom, Email aux utilisateurs et en même temps ajouter ID et Locale, Sexe dans la table FBData.
Il semble que vous mettiez tous vos modèles dans IdentityModels.cs pour que vous puissiez les mettre là. Cependant, il est préférable d'avoir une seule classe par fichier. FbData n'héritera pas d'IdentityContext, mais seulement pour votre ApplicationDbContext. –