A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
Hi GuillermoPerez-9757,
>>that the user can get the list of messages from the other table using the MessagesId and viceversa, that the table Messages could get the user the message belongs to by using its MessageGroupId...
According to my understanding, you need to configure a one-to-many relationship (a user has multiple messages, and multiple messages correspond to one user).
And you can configure a relationship via the Fluent API.
Code looks like below:
Class MyContext : DbContext
{
public DbSet<User> users { get; set; }
public DbSet<Messages> messages { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Messages>()
.HasOne(m => m.User)
.WithMany(u => u.messages);
}
}
public class User
{
public int Id { get; set; }
public string MessagesId { get; set; }
...
public List<Messages> messages { get; set; }
}
public class Messages
{
public int id { get; set; }
public string MessageGroupId{ get; set; }
...
public User User { get; set; }
}
More details you can refer to this document.
Best Regards,
Daniel Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.