Two identical class types in entity class release

I am implementing a function that allows users to follow each other. I have a database table:

User{UserId, FirstName, LastName etc.}
Followings{FollowerUserId, FollowingUserId, CreatedOnDate etc.}

So, I added the EF class:

public class Follow
    {
        [Key, Column(Order = 1)]
        public Guid FollowerUserId { get; set; }
        [Key, Column(Order = 2)]
        public Guid FollowUserId { get; set; }        
        public DateTime CreatedOnDate { get; set; }

        public virtual User Follower { get; set; }
        public virtual User Following { get; set; }
    }

The last two virtual properties are couse issue. When i call:

var model = con.Follows.Where(x => x.FollowerUserId == uid);

I get the following exception:

Invalid column name 'Following_UserId'.

The problem is probably caused by two User objects in the same class. Any idea how to do this?
UPDATE

public class User
    {

        public Guid UserId { get; set; }
        ...
        public virtual ICollection<Follow> Following { get; set; }
        public virtual ICollection<Follow> Followers { get; set; }
    }
+5
source share
1 answer

, , (FollowerUserId FollowUserId) (Follower Following) , EF . , FK [ForeignKey]:

public class Follow
{
    [Key, Column(Order = 1), ForeignKey("Follower")]
    public Guid FollowerUserId { get; set; }
    [Key, Column(Order = 2), ForeignKey("Following")]
    public Guid FollowUserId { get; set; }        

    public DateTime CreatedOnDate { get; set; }

    public virtual User Follower { get; set; }
    public virtual User Following { get; set; }
}

Edit

, . , , FK FollowUserId :

public Guid FollowingUserId { get; set; }        

... Following.

2

UPDATE: [InverseProperty], EF, :

public class Follow
{
    [Key, Column(Order = 1), ForeignKey("Follower")]
    public Guid FollowerUserId { get; set; }
    [Key, Column(Order = 2), ForeignKey("Following")]
    public Guid FollowUserId { get; set; }        

    public DateTime CreatedOnDate { get; set; }

    [InverseProperty("Followers")]  // refers to Followers in class User
    public virtual User Follower { get; set; }
    [InverseProperty("Following")]  // refers to Following in class User
    public virtual User Following { get; set; }
}
+4

All Articles