0

I want to display list of users with products of every user.

So I have this in my classes :

public partial class User
{
    public User()
    {
        Product = new HashSet<Product>();
    }

    public decimal Id { get; set; }

    [InverseProperty("UserNavigation")]
    public virtual ICollection<Product> Products { get; set; }
}

public partial class Product
{
    public decimal Id { get; set; }
    public decimal UserId { get; set; }

    [ForeignKey("UserId")]
    [InverseProperty("Products")]
    public virtual User UserNavigation { get; set; }
}

Here when I want to display list users I didn't found any product for any user count is zero for products collection but in my database I have data and notice that here the relationship between this two tables is one to many.

So what could be the problem here?

mecabmecab95
  • 91
  • 2
  • 9

0 Answers0