我在下面的第 14 行收到错误:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TimeDb.Models;
namespace TimeDb.Areas.Stock.Models
{
public class ProductAddViewModel
{
private readonly DatabaseDataContext _db = new DatabaseDataContext();
public SelectList ProductTypes;
public Product Product { get; set; }
public ProductAddViewModel()
{
Product = new Product();
PopulateLists();
}
public ProductAddViewModel(int id)
{
Product = _db.Products.Single(p => p.Id == id);
PopulateLists();
}
private void PopulateLists()
{
ProductTypes = new SelectList(_db.ProductTypes.OrderBy(pt => pt.Name), "Id", "Name");
}
}
}
现在,这只是在我尝试向 Database.cs 添加一个新字段后才出现。
我试图做的是添加一个新字段,我已在数据库表中添加。但是上面出现了错误。
我尝试更改的部分数据库代码是:
#region Product
[MetadataType(typeof(ProductMetaData))]
partial class Product
{
}
public class ProductMetaData
{
[Required]
[DisplayName("Name")]
public string Name { get; set; }
[Required]
[DisplayName("Description")]
public string Description { get; set; }
[Required]
[DisplayName("Retail Price")]
public double RetailPrice { get; set; }
[Required]
[DisplayName("Threshold")]
public int Threshold { get; set; }
[Required]
[DisplayName("Number To Keep In Stock")]
public int NumberToKeepInStock { get; set; }
[Required]
[DisplayName("Shelf")]
public string Shelf { get; set; }
}
我补充说:
[DisplayName("disabled")]
public int disabled { get; set;}
很可能我不知道调整表后调整数据库代码的最佳方法。但是当我删除上述修改时,它仍然显示相同的错误。
最好的前进方式是什么?
谢谢