Commit 0750ea4b authored by Kirill's avatar Kirill

Achievement unlocked : Припаять Entity Framework до достижения 20 лет

parent 87783561
...@@ -3,23 +3,16 @@ ...@@ -3,23 +3,16 @@
<configSections> <configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections> </configSections>
<connectionStrings>
<add name="footballDb" connectionString="data source=my.sqlite;foreign keys=true" providerName="System.Data.SQLite" />
</connectionStrings>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup> </startup>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite.EF6" />
<add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
<remove invariant="System.Data.SQLite" /><add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" /></DbProviderFactories>
</system.data>
<entityFramework> <entityFramework>
<providers> <providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" /> <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers> </providers>
</entityFramework> </entityFramework>
</configuration> </configuration>
\ No newline at end of file
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Common; using System.Data.Common;
using System.Data.Entity; using System.Data.Entity;
using System.Data.Entity.Core.Common;
using System.Data.SQLite;
using System.Data.SQLite.EF6;
using SQLite.CodeFirst; using SQLite.CodeFirst;
namespace TourDataManager { namespace TourDataManager {
[Table("Foo")]
public class Foo { public class Foo {
public long Id; public long Id{ get; set; }
public string Data;
public string Data{ get; set; }
}
public class SQLiteConfiguration : DbConfiguration
{
public SQLiteConfiguration()
{
SetProviderFactory("System.Data.SQLite", SQLiteFactory.Instance);
SetProviderFactory("System.Data.SQLite.EF6", SQLiteProviderFactory.Instance);
SetProviderServices("System.Data.SQLite", (DbProviderServices)SQLiteProviderFactory.Instance.GetService(typeof(DbProviderServices)));
}
} }
//[DbConfigurationType(typeof(Ef6CodeConfig))] //[DbConfigurationType(typeof(Ef6CodeConfig))]
...@@ -14,6 +31,8 @@ namespace TourDataManager { ...@@ -14,6 +31,8 @@ namespace TourDataManager {
public MyDbContext(DbConnection connection, bool contextOwnsConnection) public MyDbContext(DbConnection connection, bool contextOwnsConnection)
: base(connection,contextOwnsConnection){ : base(connection,contextOwnsConnection){
DbConfiguration.SetConfiguration(new SQLiteConfiguration());
Configuration.ProxyCreationEnabled = true; Configuration.ProxyCreationEnabled = true;
Configuration.LazyLoadingEnabled = true; Configuration.LazyLoadingEnabled = true;
} }
...@@ -28,6 +47,8 @@ namespace TourDataManager { ...@@ -28,6 +47,8 @@ namespace TourDataManager {
public DbSet<Foo> Foo{ get; set; } public DbSet<Foo> Foo{ get; set; }
} }
public class Db { public class Db {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment