简体   繁体   English

在ADO.NET实体框架上,DbContext对象没有表字段

[英]On ADO.NET entity framework, the DbContext object does not have a table field

I am using VS 2015 Community, Windows 10, Microsoft SQL 2016 SP1. 我正在使用VS 2015社区,Windows 10,Microsoft SQL 2016 SP1。 I added an SQL Server DB to the project. 我在项目中添加了SQL Server数据库。 Then I added a table named 'Dict' to that database. 然后,我向该数据库添加了一个名为“ Dict”的表。 图中的数据库

I am following this tutorial (at 20:00) which explains how to use ADO.NET with Visual Studio. 我正在按照本教程(在20:00)进行介绍, 该教程说明了如何在Visual Studio中使用ADO.NET。 The video is a bit outdated, but I followed the same steps to create the entity model. 该视频有些过时,但是我按照相同的步骤创建了实体模型。 But when I get to the part in 21:01, my DbContext object (seen below) returns an error when I try to access context.Dict. 但是当我在21:01到达该部分时,当我尝试访问context.Dict时,我的DbContext对象(如下所示)将返回错误。 It says no definition found for Dict. 它说没有为Dict找到定义。

    public partial class _Default : Page
      {
         protected void Page_Load(object sender, EventArgs e)
         {
            var context = new DictServerEntities1();

            var words = context.Dict;

UPDATE: 更新:

I imported some sample databases provided by Microsoft (called Northwind), and they work with EF. 我导入了Microsoft提供的一些示例数据库(称为Northwind),它们与EF一起使用。 So my table is somehow not valid for EF, I'm guessing because it does not contain a primary key. 所以我的表对EF无效,我猜是因为它不包含主键。

The answer to this was to use a table with a primary key. 答案是使用带有主键的表。 I was not using a primary key. 我没有使用主键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM