Your view models really don't make any sense. Each batch has a list of sub-batches, but then each sub-batch has a list of IDs, a list of names, and a count of the number of sub-batches.
I suspect you want something that looks like this:
public class BatchInfoView
{
public bool IsNew { get; set; }
public int BatchID { get; set; }
public string BatchName { get; set; }
public List<SubBatchInfoView> SubBatches { get; set; }
public int SubBatchCount
{
get { return SubBatches == null ? 0 : SubBatches.Count; }
}
}
public class SubBatchInfoView
{
public int SubBatchID { get; set; }
public string SubBatchName { get; set; }
}
Then you'll need to load the sub-batches as part of the query to load the batches:
var batches = db.Batches
.Include(batch => batch.SubBatches)
.Select(batch => new BatchInfoView
{
BatchID = batch.BatchID,
BatchName = batch.Name,
SubBatches = batch.SubBatches.Select(sb => new SubBatchInfoView
{
SubBatchID = sb.SubBatchID,
SubBatchName = sb.Code,
}).ToList()
})
.ToList();