Hi guys,
So I just started using System.Data.Sqlite with entity framework 6
(downloaded the latest System.Data.Sqlite from Nuget, version 1.0.91.0)
After some configuration and code, I found out that I can read from the
database but somehow write is not working.
Here's my code:
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();
}
Basically after SaveChanges, nothing was updated in the DB. However I can
read fro the DB with the data I manually populated via SQlite admin tool.
Here's my DB schema:
Table name :Demo
Field: ID - Integer Primary Key AutoIncrement
Field: Name - VARCHAR(256)
Here's my classes
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>
If anyone could point me to the right direction, that'd be fantastic,
thanks so much
Nick
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users