2017-08-23 21:00:44 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Data.Entity;
|
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Config = SockScape.Configuration;
|
2017-06-05 12:20:39 +00:00
|
|
|
|
|
2017-08-23 21:00:44 +00:00
|
|
|
|
namespace SockScape.DAL {
|
|
|
|
|
[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
|
|
|
|
|
internal partial class ScapeDb : DbContext {
|
|
|
|
|
private static readonly string Dsn;
|
|
|
|
|
|
|
|
|
|
static ScapeDb() {
|
|
|
|
|
DbConfiguration.SetConfiguration(new MySql.Data.Entity.MySqlEFConfiguration());
|
|
|
|
|
|
|
|
|
|
// fix for migrations
|
|
|
|
|
if(!Directory.GetCurrentDirectory().ToLower().Contains(":\\windows")) {
|
|
|
|
|
Dsn = "server=" + Config.Database["Server"]
|
|
|
|
|
+ ";port=" + (Config.Database["Port"] ?? "3306")
|
|
|
|
|
+ ";user id=" + Config.Database["Username"]
|
|
|
|
|
+ ";password=" + Config.Database["Password"]
|
|
|
|
|
+ ";persistsecurityinfo=True;"
|
|
|
|
|
+ "database=" + Config.Database["Database"];
|
|
|
|
|
} else {
|
|
|
|
|
Dsn = "name=ScapeDb";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ScapeDb() : base(Dsn) { }
|
|
|
|
|
|
|
|
|
|
public DbSet<User> Users { get; set; }
|
|
|
|
|
public DbSet<Origin> Origins { get; set; }
|
|
|
|
|
public DbSet<Session> Sessions { get; set; }
|
2017-08-24 21:00:52 +00:00
|
|
|
|
public DbSet<ItemMaster> ItemMaster { get; set; }
|
|
|
|
|
public DbSet<Item> Items { get; set; }
|
2017-08-23 21:00:44 +00:00
|
|
|
|
|
|
|
|
|
protected override void OnModelCreating(DbModelBuilder builder) {
|
|
|
|
|
base.OnModelCreating(builder);
|
2017-08-25 21:03:33 +00:00
|
|
|
|
|
|
|
|
|
builder.HasDefaultSchema(String.Empty);
|
|
|
|
|
|
2017-08-24 21:00:52 +00:00
|
|
|
|
builder.Properties<string>()
|
|
|
|
|
.Configure(s => s.HasMaxLength(256).HasColumnType("varchar"));
|
|
|
|
|
|
|
|
|
|
builder.Entity<ItemMaster>().ToTable("ItemMaster");
|
2017-08-23 21:00:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|