I have 2 objects.
The first entity:
public WorkItem()
{
this.Usage = new Collection<ItemUsage>();
}
public int Id { get; set; }
public string Description { get; set; }
public virtual ICollection<ItemUsage> Usage { get; set; }
and the second object:
public class ItemUsage
{
public ItemUsage()
{
}
public int Id { get; set; }
public int WorkItemId { get; set; }
public string UsedFor { get; set; }
public virtual WorkItem WorkItem { get; set; }
}
But when I try to get all work items, the usage list is empty. Even if I add include.
var all = EntitySet.Include(i => i.Usage).ToList();
False loading is disabled. Do you have any idea what is wrong?
If I check the query in dbset, there is no connection to the second table.
{SELECT
[Extent1].[Id] AS [Id],
[Extent1].[Description] AS [Description]
FROM [dbo].[WorkItem] AS [Extent1]
}
EDIT:
Configurations:
entity.HasKey(f => f.Id);
entity.Property(f => f.UsedFor).IsRequired().HasMaxLength(1000);
entity.HasRequired(f => f.WorkItem).WithMany(s => s.Usage).HasForeignKey(s => s.WorkItemId).WillCascadeOnDelete();
and
entity.HasKey(f => f.Id);
entity.Property(f => f.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
entity.Property(f => f.Description).IsRequired().HasMaxLength(1000);
entity.HasMany(s => s.Usage).WithRequired(s => s.WorkItem).HasForeignKey(s => s.WorkItemId).WillCascadeOnDelete();
source
share