我使用「實體框架DbContext」的時刻,我有異常towars.dbo未找到。這很奇怪,因爲在我的網站上,我一直在問關於towar.dbo,但沒有towars.dbo你知道問題出在哪裏嗎?實體框架添加到我的.dbo
- InnerException {"Invalid object name 'dbo.Towars'."} System.Exception {System.Data.SqlClient.SqlException}
我對Towar(在我的程序,當然不同的地方)的所有東西:
public class ProductController : Controller
{
//
// GET: /Product/
public ITowarRepository repository;
public ProductController(ITowarRepository productRepository)
{
repository = productRepository;
}
public ViewResult List()
{
return View(repository.Towar);
}
}
public interface ITowarRepository
{
IQueryable<Towar> Towar { get; }
}
public DbSet<Towar> Towar { get; set; }
public class EFTowarRepository : ITowarRepository
{
public EFDbContext context = new EFDbContext();
public IQueryable<Towar> Towar
{
get { return context.Towar; }
}
}
public class Towar
{
[Key]
public int Id_tow { get; set; }
public string Nazwa { get; set; }
public string Opis { get; set; }
public decimal Cena { get; set; }
public int Id_kat { get; set; }
}
什麼是在你的數據庫表名?是否連接到正確的數據庫? – Shyju 2012-08-03 15:58:24
連接數據庫是否正確 connectionStrings> –
RPD
2012-08-03 16:00:34