How I can use Include of the LINQ properly under MVC3?
I created .edmx file and it has all tables.
Two of them have a relashionships
UserCategories 1..0 – * Users
I guessed to use
var userCategories = db.UserCategories.Include("Users");
in order to populate Users property. But it is always empty.
(Here there is a good example how to use it. But no success.)
How do I can fix it?
P.S. POCO class
public partial class UserCategory
{
public UserCategory()
{
this.Users = new HashSet<User>();
}
public string Name { get; set; }
public System.Guid ID { get; set; }
public virtual ICollection<User> Users { get; set; }
}
Ok, first if
Usersit’s empty probably it’s because your don’t have the data in the database. Now to be specific refactor your expression like thisThis will retrieve all the users in your database which have a relation with the table UserCategory
If you just tried to obtain the users no matter the relation with the table
Disclaimer: note that this expressions are heave and bring all the records of your database used carefully