我对 mvc 很陌生,并试图了解这个概念。我正在按照这个指示来处理许多关系。但是我创建了一个接口和实体框架,并使用 ninject 将它们绑定在一起。而不是 'books' 和 'users'(就像在教程中一样),我使用 'groups' 和 'users'。我阅读了很多关于相同错误的帖子,但它们似乎并没有解决我的问题
public interface IGroups
{
IQueryable<Group> Groups { get; }
}
public class EFGroups : IGroups
{
private EFDbContextMainDb1 context = new EFDbContextMainDb1();
public IQueryable<Group> Groups
{
get;
set;
}
}
public class EFDbContextMainDb1 : DbContext
{
public DbSet<Group> tblGroup { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Group>().ToTable("tblGroup");
base.OnModelCreating(modelBuilder);
}
}
public class GroupListViewModel
{
public IEnumerable<GroupNetworkUser> GroupNetworkUsers { get; set; }
}
GroupListViewModel model = new GroupListViewModel
{
GroupNetworkUsers = testRepo.Groups.SelectMany(
group => group.Users,
(group, user) => new {
userName = user.vch_NetworkID
}
)
};
该错误适用于“GroupNetworkUsers = testRepo.Groups.SelectMany(...”。并说
Error 1 Cannot implicitly convert type 'System.Linq.IQueryable<AnonymousType#1>' to 'System.Collections.Generic.IEnumerable<Pho.Domain.Entities.GroupNetworkUser>'. An explicit conversion exists (are you missing a cast?) C:\visual_studio_project\pho\pho\Controllers\GroupsAndUsersController.cs 58 37 Pho.WebUI