【发布时间】:2014-03-01 23:04:27
【问题描述】:
我正在.NET MVC 中开发一个应用程序,我目前正在尝试从两个表(模型)中提取记录列表并通过 ViewModel 将列表发送到我的视图。下面你可以看到我的两个原始模型和视图模型
public partial class Animal
{
public int AnimalId { get; set; }
public Nullable<int> UserId { get; set; }
public string TagNo { get; set; }
public Nullable<int> Species { get; set; }
public Nullable<bool> Sex { get; set; }
public Nullable<int> AnimalBreed { get; set; }
public Nullable<System.DateTime> DOB { get; set; }
public Nullable<int> OwnershipStatus { get; set; }
public Nullable<System.DateTime> DateAdded { get; set; }
public Nullable<bool> BornOnFarm { get; set; }
public virtual Breed Breed { get; set; }
}
public partial class Breed
{
public int id { get; set; }
public Nullable<int> SpeciesID { get; set; }
public string Breed1 { get; set; }
}
public partial class CowIndexVM
{
public string TagNo { get; set; }
public string AnimalBreed { get; set; }
public Nullable<System.DateTime> DateAdded { get; set; }
}
在这里,您可以看到我用来选择记录列表的控制器的代码,然后我将在视图中的表格中显示这些代码
List <CowIndexVM> myCowIndexVM = (from animals in db.Animals
join aBreed in db.Breeds on animals.AnimalBreed equals aBreed.id
where animals.Species == 2 & animals.OwnershipStatus == 1
& animals.UserId == WebSecurity.CurrentUserId
orderby animals.DateAdded descending
select new CowIndexVM
{
TagNo = animals.TagNo,
AnimalBreed = aBreed.Breed1,
DateAdded = animals.DateAdded
}).ToList();
return View("Index", myCowIndexVM);
但是当我尝试运行它时,我得到了上面显示的错误。
有人可以帮我吗?为了清楚起见,我正在尝试在表格中显示检索到的记录
谢谢
【问题讨论】:
-
尝试使用
&&而不是&。应该是编译器错误而不是 GetEnumerator 的东西......但值得一试
标签: linq asp.net-mvc-4 viewmodel