I have a User Model
public class User {
public Guid IdGuid {get;set;}
public string Name {get;set;}
public virtual List<User> Friends {get;set;}
}
And I have second model
public class UserFriendship{
public Guid FriendShipIdGuid {get;set;}
public Guid UserIdGuid {get;set;}
public Guid FriendIdGuid {get;set;}
}
I have FluentApi code OnModelcreating
in context.
modelBuilder.Entity<User>().HasMany(u => u.Friends).WithMany().Map(c => {
c.MapLeftKey("UserIdGuid");
c.MapRightKey("FriendIdGuid");
c.ToTable("UserFriendship");
});
Problem : I already have a UserFriendship
class model. And I want to create relation about users to this model. And I am doing it with FluentApi.
But after FluentApi code executed, FriendShipIdGuid
is removed from UserFriendship
Table.
I need to create one to many relation for Users, and save it to table UserFriendship
and map it already existing class model name with UserFriendship
which element of dbset.
Can you help me please ?
As a summary, I already have UserFriendship
class. And this class contains FrientshipGuidId
(Key), UserIdGuid
, FriendIdGuid
.
I need to map, User
class one to many to itself.
And I want to save this relation on UserFriendship
class.
And I want to use Userfriendship
as dbset also.
I have
public DbSet<UserFriendship> Friendships { get;set; }
in my context.
I am using FluentApi ToTable
function to create one to many relation table.
But FluentApi code delete FriendshipIdGuid
field.