2014-02-18 2 views
0

Итак, я только начал использовать System.Data.Sqlite с сущностью framework 6 (загрузил последнюю версию System.Data.Sqlite из Nuget, версия 1.0.91.0) После некоторой конфигурации и кода я узнал, что могу читать из базы данных но как-то писать не работает.EF 6 с System.Data.SQlite SaveChanges() не работает?

Вот мой код:

using (var context = new InternalDbContext()) 
     { 
      var demo = context.DemoEntities.Where(d => d.ID == 1).FirstOrDefault(); 
      demo.Name = "TestTest"; 
      context.DemoEntities.Add(new Demo { Name = "Test" }); 
      context.SaveChanges(); 
     } 

В основном после того, как SaveChanges, ничего не обновляется в БД. Однако я могу читать DB с данными, которые я вручную заполнил с помощью инструмента администрирования SQlite.

Вот мой DB схема: Table name :Demo Field: ID - Integer Primary Key AutoIncrement Field: Name - VARCHAR(256)

Вот мои классы


public class InternalDbContext : DbContext 
{ 
    public DbSet<Demo> DemoEntities { get; set; } 

    public InternalDbContext() 
    { 
     // Turn off the Migrations, (NOT a code first Db) 
     Database.SetInitializer<InternalDbContext>(null); 
    } 

    protected override void OnModelCreating(DbModelBuilder modelBuilder) 
    { 
     // Database does not pluralize table names 
     modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); 
    } 
} 


[Table("Demo")] 
public class Demo 
{ 
    public long ID { get; set; } 
    public string Name { get; set; } 
} 

App.config

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    <sectionGroup name="common"> 
     <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" /> 
    </sectionGroup> 
    <!-- 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> 
    <common> 
    <logging> 
     <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4net"> 
     <arg key="configType" value="FILE-WATCH" /> 
     <arg key="configFile" value="log4net.config" /> 
     </factoryAdapter> 
    </logging> 
    </common> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
    <assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-1.2.13.0" newVersion="1.2.13.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> 
     <parameters> 
     <parameter value="v11.0" /> 
     </parameters> 
    </defaultConnectionFactory> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
     <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" /> 
    </providers> 
    </entityFramework> 
    <connectionStrings> 
    <add name="InternalDbContext" connectionString="Data Source=.\testdb.sqlite" providerName="System.Data.SQLite.EF6" /> 
    </connectionStrings> 
    <system.data> 
    <DbProviderFactories> 
     <remove invariant="System.Data.SQLite.EF6" /> 
     <add name="SQLite Data Provider" invariant="System.Data.SQLite.EF6" description="Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" /> 
    </DbProviderFactories> 
    </system.data> 
</configuration> 

Если кто-то может мне точку в правильном направлении, что» d быть фантастическим, спасибо огромное

Nick

+0

Вы можете проверить какие-либо журналы SQLLite, чтобы увидеть a) запрос, попавший в базу данных, и b) возникла некоторая ошибка? –

+0

Я не знаю, где журналы обычно генерируются для SQLite. У вас есть какие-то указатели? Благодаря! – littlejedi

ответ

1

Ваша ./bin/Debug/ должна содержать копию вашей базы данных testdb.sqlite. Это должно иметь изменения.

+0

Это правильно. –