Ahmadali Shafiee
Ahmadali Shafiee

Reputation: 4657

property of the class in null while the database contains it

I have these two models:

public class SystemGroup
{
    public Guid ID { get; set; }
    public string Name { get; set; }
    public virtual SystemGroup ParentGroup { get; set; }
    public virtual ICollection<SystemGroup> SubGroups { get; set; }
    public virtual ICollection<SystemGroupItem> Items { get; set; }
}

public class SystemGroupItem
{
    public Guid ID { get; set; }
    public string Name { get; set; }
    public SystemGroup Group { get; set; }
    public ICollection<Person> AppliedPersons { get; set; }
}

the problem is in this code

YarigaranDbContext context = new YarigaranDbContext();
SystemGroupItem i = context.SystemGroupItems.First();
return View(Items);

i.Group is null while I have it in my Database:

screenshot of table in database

I'm using EF version 6

Upvotes: 0

Views: 34

Answers (1)

ken2k
ken2k

Reputation: 48995

Make sure your property is virtual.

Upvotes: 1

Related Questions