я сделал именно это по ряду проектов
Например, у меня есть отношения от одного до многих от ASPNetUsers до Уведомления. Так что в моем классе ApplicationUser внутри IdentityModels.cs я есть
public virtual ICollection<Notification> Notifications { get; set; }
Мой Уведомления класс имеет обратный
public virtual ApplicationUser ApplicationUser { get; set; }
По умолчанию EF будет создать каскад удаления из уведомления на AspNetUsers которые я не хочу - так у меня также есть это в моем классе Context
modelBuilder.Entity<Notification>()
.HasRequired(n => n.ApplicationUser)
.WithMany(a => a.Notifications)
.HasForeignKey(n => n.ApplicationUserId)
.WillCascadeOnDelete(false);
Просто помните определение AspNetUSers распространяется в классе ApplicationUser внутри IdentityModels.cs который создается для вас визуальными студиями. Тогда относиться к нему как любой другой класс/таблицы в приложении
UPDATE - вот примеры полных моделей
public class ApplicationUser : IdentityUser
{
[StringLength(250, ErrorMessage = "About is limited to 250 characters in length.")]
public string About { get; set; }
[StringLength(250, ErrorMessage = "Name is limited to 250 characters in length.", MinimumLength=3)]
public string Name { get; set; }
public DateTime DateRegistered { get; set; }
public string ImageUrl { get; set; }
public virtual ICollection<Notification> Notifications { 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 Notification
{
public int ID { get; set; }
public int? CommentId { get; set; }
public string ApplicationUserId { get; set; }
public DateTime DateTime { get; set; }
public bool Viewed { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; }
public virtual Comment Comment { get; set; }
}
}
Я предполагаю, что вы используете код первого подхода. то, что я предпочел, это попытаться создать edmx для базы данных, а затем изучить классы, созданные для таблицы aspnetuser, вы получите эту идею. сначала создайте отношение к пользовательской таблице, а также на уровне уровня db –
@meajaygoel я могу спросить вас о каком-то коде, пожалуйста? – SergioPetrarca
http://www.itorian.com/2013/11/customizing-users-profile-to-add-new.html –