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>