重构代码
重构代码
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
public class baseModel<T>
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
|
||||
public T id { get; set; }
|
||||
public int is_delete { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
public class loopModel<T>:baseModel<int>
|
||||
{
|
||||
public int is_top { get; set; }
|
||||
public int sort { get; set; }
|
||||
public int is_show { get; set; }
|
||||
public int parentId { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public IList<T> children { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Const;
|
||||
using Yi.Framework.Common.IOCOptions;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Model
|
||||
{
|
||||
//Add-Migration yi-1
|
||||
//Update-Database yi-1
|
||||
public partial class DataContext : DbContext
|
||||
{
|
||||
//private readonly IOptionsMonitor<MySqlConnOptions> _optionsMonitor;
|
||||
public static string _connStr;
|
||||
public static string DbSelect = DbConst.Mysql;
|
||||
//public DataContext(IOptionsMonitor<MySqlConnOptions> optionsMonitor)
|
||||
//{
|
||||
// _optionsMonitor = optionsMonitor;
|
||||
// _connStr = _optionsMonitor.CurrentValue.WriteUrl;
|
||||
//}
|
||||
public DbContext ToWriteOrRead(string connstr)
|
||||
{
|
||||
_connStr = connstr;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
switch (DbSelect)
|
||||
{
|
||||
case DbConst.Mysql:
|
||||
var serverVersion = new MySqlServerVersion(new Version(8, 0, 21));
|
||||
optionsBuilder.UseMySql(_connStr, serverVersion); break;
|
||||
case DbConst.Sqlite:
|
||||
optionsBuilder.UseSqlite(_connStr); break;
|
||||
case DbConst.Sqlserver:
|
||||
optionsBuilder.UseSqlServer(_connStr);break;
|
||||
case DbConst.Oracle:
|
||||
optionsBuilder.UseOracle(_connStr);break;
|
||||
default:
|
||||
Console.WriteLine("错误!请确保你选择了正确的数据库!");break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,239 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Yi.Framework.Model;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Yi.Framework.Model.Migrations
|
||||
{
|
||||
[DbContext(typeof(DataContext))]
|
||||
[Migration("20220221034128_yi-1")]
|
||||
partial class yi1
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.1")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
modelBuilder.Entity("menurole", b =>
|
||||
{
|
||||
b.Property<int>("menusid")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("rolesid")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("menusid", "rolesid");
|
||||
|
||||
b.HasIndex("rolesid");
|
||||
|
||||
b.ToTable("menurole");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("roleuser", b =>
|
||||
{
|
||||
b.Property<int>("rolesid")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("usersid")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("rolesid", "usersid");
|
||||
|
||||
b.HasIndex("usersid");
|
||||
|
||||
b.ToTable("roleuser");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.menu", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("icon")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("is_delete")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("is_show")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("is_top")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("menu_name")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int?>("mouldid")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("parentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("router")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("sort")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.HasIndex("mouldid");
|
||||
|
||||
b.ToTable("menu");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.mould", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("is_delete")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("mould_name")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("url")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("mould");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.role", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("introduce")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("is_delete")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("role_name")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("role");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.user", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("address")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int?>("age")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("email")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("icon")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("introduction")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("ip")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("is_delete")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("nick")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("password")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("phone")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("username")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("user");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.visit", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("is_delete")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("num")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("time")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("visit");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("menurole", b =>
|
||||
{
|
||||
b.HasOne("Yi.Framework.Model.Models.menu", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("menusid")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Yi.Framework.Model.Models.role", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("rolesid")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("roleuser", b =>
|
||||
{
|
||||
b.HasOne("Yi.Framework.Model.Models.role", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("rolesid")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Yi.Framework.Model.Models.user", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("usersid")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.menu", b =>
|
||||
{
|
||||
b.HasOne("Yi.Framework.Model.Models.mould", "mould")
|
||||
.WithMany()
|
||||
.HasForeignKey("mouldid");
|
||||
|
||||
b.Navigation("mould");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,221 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Yi.Framework.Model.Migrations
|
||||
{
|
||||
public partial class yi1 : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterDatabase()
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "mould",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
mould_name = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
url = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
is_delete = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_mould", x => x.id);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "role",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
role_name = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
introduce = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
is_delete = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_role", x => x.id);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "user",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
username = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
password = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
icon = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
nick = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
email = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
ip = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
age = table.Column<int>(type: "int", nullable: true),
|
||||
introduction = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
address = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
phone = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
is_delete = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_user", x => x.id);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "visit",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
time = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
||||
num = table.Column<int>(type: "int", nullable: false),
|
||||
is_delete = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_visit", x => x.id);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "menu",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
icon = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
router = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
menu_name = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
mouldid = table.Column<int>(type: "int", nullable: true),
|
||||
is_delete = table.Column<int>(type: "int", nullable: false),
|
||||
is_top = table.Column<int>(type: "int", nullable: false),
|
||||
sort = table.Column<int>(type: "int", nullable: false),
|
||||
is_show = table.Column<int>(type: "int", nullable: false),
|
||||
parentId = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_menu", x => x.id);
|
||||
table.ForeignKey(
|
||||
name: "FK_menu_mould_mouldid",
|
||||
column: x => x.mouldid,
|
||||
principalTable: "mould",
|
||||
principalColumn: "id");
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "roleuser",
|
||||
columns: table => new
|
||||
{
|
||||
rolesid = table.Column<int>(type: "int", nullable: false),
|
||||
usersid = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_roleuser", x => new { x.rolesid, x.usersid });
|
||||
table.ForeignKey(
|
||||
name: "FK_roleuser_role_rolesid",
|
||||
column: x => x.rolesid,
|
||||
principalTable: "role",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_roleuser_user_usersid",
|
||||
column: x => x.usersid,
|
||||
principalTable: "user",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "menurole",
|
||||
columns: table => new
|
||||
{
|
||||
menusid = table.Column<int>(type: "int", nullable: false),
|
||||
rolesid = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_menurole", x => new { x.menusid, x.rolesid });
|
||||
table.ForeignKey(
|
||||
name: "FK_menurole_menu_menusid",
|
||||
column: x => x.menusid,
|
||||
principalTable: "menu",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_menurole_role_rolesid",
|
||||
column: x => x.rolesid,
|
||||
principalTable: "role",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_menu_mouldid",
|
||||
table: "menu",
|
||||
column: "mouldid");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_menurole_rolesid",
|
||||
table: "menurole",
|
||||
column: "rolesid");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_roleuser_usersid",
|
||||
table: "roleuser",
|
||||
column: "usersid");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "menurole");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "roleuser");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "visit");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "menu");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "role");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "user");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "mould");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,237 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Yi.Framework.Model;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Yi.Framework.Model.Migrations
|
||||
{
|
||||
[DbContext(typeof(DataContext))]
|
||||
partial class DataContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.1")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
modelBuilder.Entity("menurole", b =>
|
||||
{
|
||||
b.Property<int>("menusid")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("rolesid")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("menusid", "rolesid");
|
||||
|
||||
b.HasIndex("rolesid");
|
||||
|
||||
b.ToTable("menurole");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("roleuser", b =>
|
||||
{
|
||||
b.Property<int>("rolesid")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("usersid")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("rolesid", "usersid");
|
||||
|
||||
b.HasIndex("usersid");
|
||||
|
||||
b.ToTable("roleuser");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.menu", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("icon")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("is_delete")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("is_show")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("is_top")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("menu_name")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int?>("mouldid")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("parentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("router")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("sort")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.HasIndex("mouldid");
|
||||
|
||||
b.ToTable("menu");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.mould", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("is_delete")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("mould_name")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("url")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("mould");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.role", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("introduce")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("is_delete")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("role_name")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("role");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.user", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("address")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int?>("age")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("email")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("icon")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("introduction")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("ip")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("is_delete")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("nick")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("password")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("phone")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("username")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("user");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.visit", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("is_delete")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("num")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("time")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("visit");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("menurole", b =>
|
||||
{
|
||||
b.HasOne("Yi.Framework.Model.Models.menu", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("menusid")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Yi.Framework.Model.Models.role", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("rolesid")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("roleuser", b =>
|
||||
{
|
||||
b.HasOne("Yi.Framework.Model.Models.role", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("rolesid")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Yi.Framework.Model.Models.user", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("usersid")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yi.Framework.Model.Models.menu", b =>
|
||||
{
|
||||
b.HasOne("Yi.Framework.Model.Models.mould", "mould")
|
||||
.WithMany()
|
||||
.HasForeignKey("mouldid");
|
||||
|
||||
b.Navigation("mould");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Yi.Framework.Model.ModelFactory
|
||||
{
|
||||
public static class DbContextExtend
|
||||
{
|
||||
public static DbContext ToWriteOrRead(this DbContext dbContext, string conn)
|
||||
{
|
||||
if (dbContext is DataContext)
|
||||
{
|
||||
|
||||
var context= (DataContext)dbContext; // context 是 EFCoreContext 实例;
|
||||
|
||||
return context.ToWriteOrRead(conn);
|
||||
}
|
||||
else
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Yi.Framework.Common.Enum;
|
||||
using Yi.Framework.Common.IOCOptions;
|
||||
|
||||
namespace Yi.Framework.Model.ModelFactory
|
||||
{
|
||||
public class DbContextFactory : IDbContextFactory
|
||||
{
|
||||
|
||||
private DbContext _Context = null;
|
||||
|
||||
private DbConnOptions _readAndWrite = null;
|
||||
|
||||
public static bool MutiDB_Enabled = false;
|
||||
//private static int _iSeed = 0;//应该long
|
||||
|
||||
/// <summary>
|
||||
///能把链接信息也注入进来
|
||||
///需要IOptionsMonitor
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
public DbContextFactory(DbContext context, IOptionsMonitor<DbConnOptions> options)
|
||||
{
|
||||
_readAndWrite = options.CurrentValue;
|
||||
this._Context = context;
|
||||
}
|
||||
public DbContext ConnWriteOrRead(WriteAndReadEnum writeAndRead)
|
||||
{
|
||||
//判断枚举,不同的枚举可以创建不同的Context 或者更换Context链接;
|
||||
if (MutiDB_Enabled)
|
||||
{
|
||||
switch (writeAndRead)
|
||||
{
|
||||
case WriteAndReadEnum.Write:
|
||||
ToWrite();
|
||||
break; //选择链接//更换_Context链接 //选择链接
|
||||
case WriteAndReadEnum.Read:
|
||||
ToRead();
|
||||
break; //选择链接//更换_Context链接
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ToWrite();
|
||||
}
|
||||
|
||||
return _Context;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更换成主库连接
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private void ToWrite()
|
||||
{
|
||||
string conn = _readAndWrite.WriteUrl;
|
||||
//_Context.Database.GetDbConnection().;
|
||||
_Context.ToWriteOrRead(conn);
|
||||
}
|
||||
|
||||
|
||||
private static int _iSeed = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 更换成主库连接
|
||||
///
|
||||
/// ///策略---数据库查询的负载均衡
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private void ToRead()
|
||||
{
|
||||
string conn = string.Empty;
|
||||
{
|
||||
// //随机
|
||||
//int Count= _readAndWrite.ReadConnectionList.Count;
|
||||
//int index= new Random().Next(0, Count);
|
||||
//conn = _readAndWrite.ReadConnectionList[index];
|
||||
}
|
||||
{
|
||||
//来一个轮询
|
||||
conn = this._readAndWrite.ReadUrl[_iSeed++ % this._readAndWrite.ReadUrl.Count];//轮询;
|
||||
}
|
||||
{
|
||||
///是不是可以直接配置到配置文件里面
|
||||
}
|
||||
_Context.ToWriteOrRead(conn);
|
||||
}
|
||||
|
||||
//public DbContext CreateContext()
|
||||
//{
|
||||
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Yi.Framework.Common.Enum;
|
||||
|
||||
namespace Yi.Framework.Model.ModelFactory
|
||||
{
|
||||
public interface IDbContextFactory
|
||||
{
|
||||
public DbContext ConnWriteOrRead(WriteAndReadEnum writeAndRead);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
public class menu :loopModel<menu>,ITreeModel<menu>
|
||||
{
|
||||
public string icon { get; set; }
|
||||
public string router { get; set; }
|
||||
public string menu_name { get; set; }
|
||||
|
||||
public List<role> roles { get; set; }
|
||||
public mould mould { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
public class mould:baseModel<int>
|
||||
{
|
||||
public string mould_name { get; set; }
|
||||
public string url { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
public class role:baseModel<int>
|
||||
{
|
||||
public string role_name { get; set; }
|
||||
public string introduce { get; set; }
|
||||
|
||||
|
||||
public List<menu> menus { get; set; }
|
||||
public List<user> users { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -7,21 +7,19 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
public class user:baseModel<int>
|
||||
public class User
|
||||
{
|
||||
public string username { get; set; }
|
||||
public string password { get; set; }
|
||||
public string icon { get; set; }
|
||||
public string nick { get; set; }
|
||||
public string email { get; set; }
|
||||
public string ip { get; set; }
|
||||
public int? age { get; set; }
|
||||
public string introduction { get; set; }
|
||||
public string address { get; set; }
|
||||
public string phone { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string Icon { get; set; }
|
||||
public string Nick { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string Ip { get; set; }
|
||||
public int? Age { get; set; }
|
||||
public string Introduction { get; set; }
|
||||
public string Address { get; set; }
|
||||
public string Phone { get; set; }
|
||||
|
||||
public List<role> roles { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
public class visit:baseModel<int>
|
||||
{
|
||||
public DateTime time { get; set; }
|
||||
public int num { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Model
|
||||
{
|
||||
public partial class DataContext :DbContext
|
||||
{
|
||||
public DbSet<menu> menu { get; set; }
|
||||
public DbSet<mould> mould { get; set; }
|
||||
public DbSet<role> role { get; set; }
|
||||
public DbSet<user> user { get; set; }
|
||||
public DbSet<visit> visit { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
<#@ template debug="false" hostspecific="true" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.IO" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
<#@ output extension=".cs" #>
|
||||
<#
|
||||
string solutionsPath = Host.ResolveAssemblyReference("$(SolutionDir)");//获取解决方案路径
|
||||
string dirPath= Path.Combine(solutionsPath,@"Yi.Framework.Model\Models\");
|
||||
DirectoryInfo dir = new DirectoryInfo(dirPath);
|
||||
FileInfo[] finfo = dir.GetFiles();
|
||||
string filenames = string.Empty;
|
||||
List<string> filenameList = new List<string>();
|
||||
for (int i = 0; i < finfo.Length; i++)
|
||||
{
|
||||
filenames = finfo[i].Name ;
|
||||
string[] f=filenames.Split('.');
|
||||
filenameList.Add(f[0]);
|
||||
}
|
||||
|
||||
|
||||
#>
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Model
|
||||
{
|
||||
public partial class DataContext :DbContext
|
||||
{
|
||||
<# foreach(string k in filenameList){
|
||||
#>
|
||||
public DbSet<<#=k #>> <#=k #> { get; set; }
|
||||
<# } #>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,15 +5,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NEST" Version="7.16.0" />
|
||||
<PackageReference Include="Oracle.EntityFrameworkCore" Version="6.21.4" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -25,10 +17,6 @@
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<LastGenOutput>T4DaraContext.cs</LastGenOutput>
|
||||
</None>
|
||||
<None Update="T4DataContext.tt">
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<LastGenOutput>T4DataContext.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -41,11 +29,11 @@
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>T4DaraContext.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="T4DataContext.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>T4DataContext.tt</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="BaseModels\" />
|
||||
<Folder Include="ModelFactory\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user