I am using Identity, which has its own context.
public class ApplicationUser : IdentityUser {
I also have other objects like this
public class Comment{ public int Id {get;set;} public string Message{get;set;} public DateTime Time{get;set;} }
which are used in my other context
public class MyContext :DbContext { public DbSet<Comment> Comments { get; set; }
Question. I want the object of my comment to have an author property, so I will have something like
public class Comment{ public int Id {get;set;} public string Message{get;set;} public DateTime Time{get;set;} public virtual ApplicationUser Author {get;set;} }
but ApplicationUser is in a different context, albeit in the same database. I bet it's impossible.
How to implement this correctly? Should I move DbSets from MyContext to IdentityContext, so I can freely use code like this
public virtual ApplicationUser Author {get;set;}
or should I leave it in a different context, but add something like
public string AuthorId {get;set}
and do some workarounds to get author information from different contexts every time I need it? Or something else?
thanks
Edit
Ok, I got something like this:
public class ApplicationUser : IdentityUser { public virtual UserProfile UserProfile { get; set; } } public class UserProfile { [Key, ForeignKey("ApplicationUser")] public string Id { get; set; }
But how should I use the link to the authorβs comment? Like this? That way, it won't be linked through an EF relationship, and will I just populate UserProfileId somewhere in the code myself?
public class Comment{ public int Id {get;set;} public string UserProfileId{get;set;} }
Is this the right thing to do?