using SqlSugar; namespace AssetManager.Data; public class InitDatabase { public static void Main() { var db = SqlSugarConfig.GetSqlSugarClient(); try { db.CodeFirst.InitTables( typeof(User), typeof(Strategy), typeof(Portfolio) ); Console.WriteLine("数据库表创建成功!"); InsertSampleData(db); } catch (Exception ex) { Console.WriteLine($"数据库初始化失败: {ex.Message}"); } } private static void InsertSampleData(ISqlSugarClient db) { var now = DateTime.Now; db.Insertable(new Strategy { Id = "hfea", UserId = "system", Alias = "HFEA 风险平价策略", Type = "risk_parity", Config = "{\"cycle\": \"quarter\", \"threshold\": 0.05, \"allocation\": {\"UPRO\": 0.6, \"TMF\": 0.4}}\n", CreatedAt = now, UpdatedAt = now }).ExecuteCommand(); Console.WriteLine("示例数据插入成功!"); } }