2016-10-31 45 views
1

我下面的代碼工作。它在我的One Repository中提取每個項目的列表。指定的包含路徑無效。 EntityType不聲明導航屬性的名稱

當我添加我的第二張桌子將所有物品拉出該桌子時,我得到了以下錯誤,在我的DataTwo上,我無法弄清楚爲什麼它會拋出這個錯誤,因爲第一個按照完全相同的方式編程。

「A指定包含路徑是無效的。在的EntityType不具有名稱聲明導航屬性」

視圖模型

public IList<OneVM> Ones { get; set; } 
public IList<TwoVM> Twos { get; set; } 
public ViewModelVM() 
{ 
    this.Ones = new List<OneVM>(); 
    this.Twos = new List<TwoVM>(); 
} 

工作原始代碼以下(控制器)

public ActionResult Directory() 
{ 
    var vm = new ViewModelVM(); 
    var datas = _OneRepository.GetData(); 
    vm.Datas = _mapper.Map<IList<DataVM>>(datas.OrderBy(i => i.Name)); 
    return View(vm); 
} 

期望的B (控制器)

public ActionResult Directory() 
    { 
var vm = new FormDirectoryVM(); 
      var datas = _OneRepository.GetData(); 
      var datasTwo= _TwoRepository.GetMoreData(); 
      vm.Datas = _mapper.Map<IList<DataVM>>(datas.OrderBy(i => i.Name)); 
     return View(vm); 
      vm.DatasTwo= _mapper.Map<IList<DataTwoVM>>(datasTwo); 
return View(vm); 
} 
+0

'_OneRepository.GetData()AsEnumerable()CONCAT(_TwoRepository.GetMoreData());' – haim770

+0

恐怕這給了我同樣的錯誤。 – BlowFish

回答

1

問題是我的知識庫。我包括了一些不需要的東西。

public IEnumerable<Two> GetMoreData() 
     { 
      return _context.Twos 
       .Include(i => i.Title) // I don't need this line 
       .Include(i => i.Description) // I don't need this line either 
       .Include(i => i.Keywords) 
       .Include(j => j.Text) // Or this Line 
       .Where(i => !i.IsDeleted) 
      ; 
     } 
相關問題