probably going to switch away from sqlite
e
This commit is contained in:
parent
4d1f62b7ed
commit
c8b83456c1
9 changed files with 133 additions and 55 deletions
|
@ -14,9 +14,9 @@
|
|||
</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" />
|
||||
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
|
||||
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
|
||||
</providers>
|
||||
</entityFramework>
|
||||
<system.data>
|
||||
|
@ -30,4 +30,16 @@
|
|||
<connectionStrings>
|
||||
<add name="Database" connectionString="data source=scape.db" providerName="System.Data.SQLite.EF6" />
|
||||
</connectionStrings>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Data.SQLite" publicKeyToken="db937bc2d44ff139" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-1.0.105.0" newVersion="1.0.105.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Data.SQLite.EF6" publicKeyToken="db937bc2d44ff139" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-1.0.105.0" newVersion="1.0.105.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
|
@ -44,15 +44,13 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>packages\EntityFramework.6.0.0\lib\net45\EntityFramework.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<HintPath>packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>packages\EntityFramework.6.0.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<HintPath>packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SQLite.Designer">
|
||||
<HintPath>..\..\..\..\..\..\Program Files (x86)\System.Data.SQLite\2015\bin\SQLite.Designer.dll</HintPath>
|
||||
<Reference Include="log4net, Version=1.2.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||
<HintPath>packages\log4net.2.0.5\lib\net45-full\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
|
@ -65,6 +63,9 @@
|
|||
<HintPath>packages\System.Data.SQLite.EF6.1.0.105.0\lib\net46\System.Data.SQLite.EF6.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Data.SQLite.EF6.Migrations, Version=1.0.104.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>packages\System.Data.SQLite.EF6.Migrations.1.0.104\lib\System.Data.SQLite.EF6.Migrations.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Data.SQLite.Linq, Version=1.0.105.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
|
||||
<HintPath>packages\System.Data.SQLite.Linq.1.0.105.0\lib\net46\System.Data.SQLite.Linq.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
|
@ -80,6 +81,8 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DAL\Item.cs" />
|
||||
<Compile Include="DAL\ItemDefinition.cs" />
|
||||
<Compile Include="DAL\ScapeDb.cs" />
|
||||
<Compile Include="DAL\Session.cs" />
|
||||
<Compile Include="DAL\User.cs" />
|
||||
|
@ -137,8 +140,7 @@
|
|||
<Error Condition="!Exists('packages\Costura.Fody.1.4.0\build\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Costura.Fody.1.4.0\build\Costura.Fody.targets'))" />
|
||||
</Target>
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>COPY "$(ProjectDir)scape.db" "$(TargetDir)"
|
||||
XCOPY "$(ProjectDir)Assets" "$(TargetDir)" /Y</PostBuildEvent>
|
||||
<PostBuildEvent>XCOPY "$(ProjectDir)Assets" "$(TargetDir)" /Y</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<Import Project="packages\Fody.2.0.4\build\dotnet\Fody.targets" Condition=" '$(Configuration)' == 'Release' " />
|
||||
<Import Project="packages\Costura.Fody.1.4.0\build\Costura.Fody.targets" Condition=" '$(Configuration)' == 'Release' " />
|
||||
|
|
22
server/DAL/Item.cs
Normal file
22
server/DAL/Item.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CircleScape.DAL {
|
||||
public class Item {
|
||||
public long Id { get; set; }
|
||||
|
||||
[Index("ItemItemDefinitionId")]
|
||||
public long DefinitionId { get; set; }
|
||||
public virtual ItemDefinition Definition { get; set; }
|
||||
|
||||
[Index("ItemUserId")]
|
||||
public long UserId { get; set; }
|
||||
public virtual User User { get; set; }
|
||||
|
||||
public long Quantity { get; set; }
|
||||
}
|
||||
}
|
22
server/DAL/ItemDefinition.cs
Normal file
22
server/DAL/ItemDefinition.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Data.Entity.Spatial;
|
||||
|
||||
namespace CircleScape.DAL {
|
||||
public partial class ItemDefinition {
|
||||
public long Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Sheet { get; set; }
|
||||
public long Offset { get; set; }
|
||||
|
||||
public bool Stackable { get; set; } = false;
|
||||
|
||||
public virtual ICollection<Item> Items { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,22 +1,55 @@
|
|||
namespace CircleScape.DAL {
|
||||
using System;
|
||||
using System.Data.Entity;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Data.Entity.Migrations;
|
||||
using System.Data.SQLite.EF6.Migrations;
|
||||
|
||||
namespace CircleScape.DAL {
|
||||
public partial class ScapeDb : DbContext {
|
||||
static ScapeDb() {
|
||||
Database.SetInitializer(
|
||||
new MigrateDatabaseToLatestVersion<ScapeDb, ScapeDbMigrationConfig>(true)
|
||||
);
|
||||
}
|
||||
|
||||
public ScapeDb() : base("name=Database") {
|
||||
|
||||
public partial class Database : DbContext {
|
||||
public Database()
|
||||
: base("name=Database") {
|
||||
}
|
||||
|
||||
public virtual DbSet<Session> Sessions { get; set; }
|
||||
public virtual DbSet<User> Users { get; set; }
|
||||
public virtual DbSet<Item> Items { get; set; }
|
||||
public virtual DbSet<ItemDefinition> ItemDefinitions { get; set; }
|
||||
|
||||
protected override void OnModelCreating(DbModelBuilder modelBuilder) {
|
||||
modelBuilder.Entity<User>()
|
||||
.HasMany(e => e.Sessions)
|
||||
.WithRequired(e => e.User)
|
||||
.WillCascadeOnDelete(false);
|
||||
.HasForeignKey(e => e.UserId)
|
||||
.WillCascadeOnDelete(true);
|
||||
|
||||
modelBuilder.Entity<User>()
|
||||
.HasMany(e => e.Items)
|
||||
.WithRequired(e => e.User)
|
||||
.HasForeignKey(e => e.UserId)
|
||||
.WillCascadeOnDelete(true);
|
||||
|
||||
modelBuilder.Entity<ItemDefinition>()
|
||||
.HasMany(e => e.Items)
|
||||
.WithRequired(e => e.Definition)
|
||||
.HasForeignKey(e => e.DefinitionId)
|
||||
.WillCascadeOnDelete(true);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class ScapeDbMigrationConfig
|
||||
: DbMigrationsConfiguration<ScapeDb>
|
||||
{
|
||||
public ScapeDbMigrationConfig() {
|
||||
AutomaticMigrationsEnabled = true;
|
||||
AutomaticMigrationDataLossAllowed = true;
|
||||
SetSqlGenerator("System.Data.SQLite", new SQLiteMigrationSqlGenerator());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,18 @@
|
|||
namespace CircleScape.DAL
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Data.Entity.Spatial;
|
||||
|
||||
public partial class Session
|
||||
{
|
||||
namespace CircleScape.DAL {
|
||||
public partial class Session {
|
||||
public long Id { get; set; }
|
||||
|
||||
[Index("SessionUserId")]
|
||||
public long UserId { get; set; }
|
||||
public virtual User User { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(2147483647)]
|
||||
public string IpAddress { get; set; }
|
||||
|
||||
public virtual User User { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,17 @@
|
|||
namespace CircleScape.DAL
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Data.Entity.Spatial;
|
||||
|
||||
public partial class User
|
||||
{
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
|
||||
public User()
|
||||
{
|
||||
Sessions = new HashSet<Session>();
|
||||
}
|
||||
|
||||
namespace CircleScape.DAL {
|
||||
public partial class User {
|
||||
public long Id { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(2147483647)]
|
||||
public string Username { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(2147483647)]
|
||||
public string Password { get; set; }
|
||||
|
||||
public long? Joined { get; set; }
|
||||
|
@ -29,13 +19,11 @@ namespace CircleScape.DAL
|
|||
public long? LastLogin { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(2147483647)]
|
||||
public string JoinedIp { get; set; }
|
||||
|
||||
[StringLength(2147483647)]
|
||||
public string LastIp { get; set; }
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
|
||||
public virtual ICollection<Session> Sessions { get; set; }
|
||||
public virtual ICollection<Item> Items { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ using Square;
|
|||
namespace CircleScape {
|
||||
class Entrypoint {
|
||||
static void Main(string[] args) {
|
||||
var db = new Database();
|
||||
var db = new ScapeDb();
|
||||
var users = db.Users.ToList();
|
||||
|
||||
var server = new Kneesocks.Server<PendingConnection>(6770, PoolManager.Pending);
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Costura.Fody" version="1.4.0" targetFramework="net46" developmentDependency="true" />
|
||||
<package id="EntityFramework" version="6.0.0" targetFramework="net46" />
|
||||
<package id="EntityFramework" version="6.1.3" targetFramework="net46" />
|
||||
<package id="Fody" version="2.0.4" targetFramework="net46" developmentDependency="true" />
|
||||
<package id="log4net" version="2.0.5" targetFramework="net46" />
|
||||
<package id="System.Data.SQLite" version="1.0.105.0" targetFramework="net46" />
|
||||
<package id="System.Data.SQLite.Core" version="1.0.105.0" targetFramework="net46" />
|
||||
<package id="System.Data.SQLite.EF6" version="1.0.105.0" targetFramework="net46" />
|
||||
<package id="System.Data.SQLite.EF6.Migrations" version="1.0.104" targetFramework="net46" />
|
||||
<package id="System.Data.SQLite.Linq" version="1.0.105.0" targetFramework="net46" />
|
||||
</packages>
|
Loading…
Reference in a new issue