Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# EF Code first查询返回0_C#_Database_Entity Framework_Code First - Fatal编程技术网

C# EF Code first查询返回0

C# EF Code first查询返回0,c#,database,entity-framework,code-first,C#,Database,Entity Framework,Code First,我尝试从数据库中的表中获取所有行,但列表返回空。 数据库中的行的屏幕截图: 这是我的app.config <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink

我尝试从数据库中的表中获取所有行,但列表返回空。 数据库中的行的屏幕截图:


这是我的app.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

如果您使用的是SQL CE,则很可能是在bin\debug文件夹中创建了数据库文件,但您指向了其他地方


如果您使用的是
DropCreateDatabaseAlways

视图在哪里,则尤其如此。。??和你的连接字符串,因为你提供的代码很好。显示你的web配置数据库连接。检查连接字符串并找出你有多少个数据库副本。这是我的app.config
public class FilmsContext : DbContext
    {

        public FilmsContext() : base("FilmsContext")
        {
        }

        public DbSet<Films> Films { get; set; }
    }
public class Films
    {
        public int Id { get; set; }
        public string name { get; set; }
        public string beschrijving { get; set; }
        public string afbeelding { get; set; }
        public string auteur { get; set; }
        public int sterren { get; set; }
        public string websitelink { get; set; }
        public DateTime datum { get; set; }
    }
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>