/// <summary> /// 映射物理表 /// </summary> /// <param name="absTable">抽象表类型</param> /// <param name="targetTableName">目标物理表名</param> /// <returns></returns> public static Type MapTable(Type absTable, string targetTableName) { var config = TypeBuilderHelper.GetConfig(absTable); config.AssemblyName = "EFCore.Sharding"; var theTableAttribute = config.Attributes .Where(x => x.Attribute == typeof(TableAttribute)) .FirstOrDefault(); if (theTableAttribute != null) { theTableAttribute.ConstructorArgs[0] = targetTableName; } config.FullName = $"EFCore.Sharding.{targetTableName}"; return(TypeBuilderHelper.BuildType(config)); }
static void Main(string[] args) { //IRepository db1 = DbFactory.GetRepository("oracle", DatabaseType.Oracle); //IRepository db2 = DbFactory.GetRepository("oracle2", DatabaseType.Oracle); //var list = db1.GetList<Base_User>(); //var list2 = db2.GetList<Base_User>(); var db = DbFactory.GetRepository(); db.HandleSqlLog = Console.WriteLine; string tableName = "Base_User1"; var typeConfig = TypeBuilderHelper.GetConfig(typeof(Base_User)); typeConfig.FullName = tableName; typeConfig.Attributes[0].ConstructorArgs[0] = tableName; var type = TypeBuilderHelper.BuildType(typeConfig); var type2 = TypeBuilderHelper.BuildType(typeConfig); var properties = type.GetProperties(); Console.WriteLine(type == type2); Base_User base_User = new Base_User { Id = GuidHelper.GenerateKey(), UserId = GuidHelper.GenerateKey(), UserName = GuidHelper.GenerateKey() }; Base_User base_User2 = new Base_User { Id = GuidHelper.GenerateKey(), UserId = GuidHelper.GenerateKey(), UserName = GuidHelper.GenerateKey() }; db.Insert(base_User.ToJson().ToObject(type)); db.Insert(base_User2.ChangeType(type2)); Console.WriteLine("完成"); Console.ReadLine(); }