我正在使用带有 MVC4 的实体框架。我不知道如何将我的 ViewModel 添加到我的 dbcontext 中。就像在我的 DbContext 中声明它一样简单吗?基本上我希望在控制器中使用视图模型并将其传递到我的视图。我在尝试实现这一目标时遇到了很多问题。
namespace BagInventory.Models
{
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
public partial class FreshouseSalesEntities : DbContext
{
public FreshouseSalesEntities()
: base("name=FreshouseSalesEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public DbSet<Materials_Packer> Materials_Packer { get; set; }
public DbSet<Materials_Product> Materials_Product { get; set; }
public DbSet<Materials_PackerProduct> Materials_PackerProduct { get; set; }
public DbSet<Materials_Vendor> Materials_Vendor { get; set; }
public DbSet<Materials_Log> Materials_Log { get; set; }
//Below is my view …
Run Code Online (Sandbox Code Playgroud)