2016-03-31 14 views
0

データベースのテーブルからすべての行を取得しようとしましたが、リストは空に戻ります。 スクリーンショットであれば、データベース内の行: https://gyazo.com/37957807543227e4c6b2df9d30b1b970EFコードの最初のクエリは0を返します

///Database connectie 
var dbconn = new FilmsContext(); 


///Alles uit de database halen 
List<Films> list = dbconn.Films.ToList(); 

データベースのセットアップ

public class FilmsContext : DbContext 
    { 

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

     public DbSet<Films> Films { get; set; } 
    } 

これは私のapp.configである

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> 
+1

Viewsはどこですか? あなたが提供するコードは問題ないので、あなたの接続文字列。 – BilalAhmed

+0

Web設定DB接続を表示します。 –

+0

接続文字列を確認して、データベースのコピー数を確認してください。 –

答えて

0

SQL CEを使用している場合、データベースファイルはbin \ debugフォルダに作成されていますが、別の場所を指している可能性があります。

DropCreateDatabaseAlwaysを使用している場合は特にそうです。

関連する問題