当前位置: 首页>>代码示例>>C#>>正文


C# SessionFactory.FindBySql方法代码示例

本文整理汇总了C#中SessionFactory.FindBySql方法的典型用法代码示例。如果您正苦于以下问题:C# SessionFactory.FindBySql方法的具体用法?C# SessionFactory.FindBySql怎么用?C# SessionFactory.FindBySql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SessionFactory的用法示例。


在下文中一共展示了SessionFactory.FindBySql方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Index

        //[Priviledge(Name = "首页", IsMenu = true, IsEntry = true, Position = 1)]
        public ActionResult Index()
        {
            using (var session = new SessionFactory().OpenSession())
            {
                const string accountNavigationSql =
                    "SELECT * FROM `navigations` WHERE `type` < 4 AND ((`auth_code` = 0) OR (`id` IN ( SELECT `navigation_id` FROM `navigation_priviledges` WHERE (`flag` = 1 AND `owner_id` IN (SELECT `role_id` FROM `account_role_refs` WHERE `account_id` IN ( SELECT `id` FROM `accounts` WHERE `name` = '{0}'))) OR (`flag` = 2 AND `owner_id` IN ( SELECT `id` FROM `accounts` WHERE `name` = '{0}'))))) ORDER BY `order_id` asc";
                var accountNavs =
                    session.FindBySql<Navigation>(string.Format(accountNavigationSql, CurrentAccountNo));
                Session.Add(Const.AccountMenuItems, accountNavs);

                const string rolePinNavigationSql =
                    "SELECT n.* FROM `account_navigation_refs` r LEFT JOIN `navigations` n ON r.`navigation_id` = n.`id` WHERE r.`type` = 1 AND r.`owner_id` IN (SELECT `role_id` FROM `account_role_refs` WHERE `account_id` IN ( SELECT `id` FROM `accounts` WHERE `name` = '{0}')) ORDER BY r.`order_id` ASC";
                var pinRoleNavs =
                    session.FindBySql<Navigation>(string.Format(rolePinNavigationSql, CurrentAccountNo));
                Session.Add(Const.RolePinnedTask, pinRoleNavs);

                const string accountPinNavigationSql =
                    "SELECT n.* FROM `account_navigation_refs` r LEFT JOIN `navigations` n ON r.`navigation_id` = n.`id` WHERE r.`type` = 2 AND r.`owner_id` IN ( SELECT `id` FROM `accounts` WHERE `name` = '{0}') ORDER BY r.`order_id` ASC";
                var pinAccountNavs =
                    session.FindBySql<Navigation>(string.Format(accountPinNavigationSql, CurrentAccountNo));
                Session.Add(Const.AccountPinnedTask, pinAccountNavs);

                var model = session.Load<Account>(m => m.Name.Equals(CurrentAccountNo));

                return View(model);
            }
        }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:28,代码来源:PortalController.cs

示例2: GetModelCodeFormDb

        public static string GetModelCodeFormDb(string tableName)
        {
            using (var session = new SessionFactory().OpenSession())
            {
                var model = session.FindBySql<DbTable>("show full fields from " + tableName);
                if (model == null || model.Count == 0)
                {
                    // table不存在
                    return null;
                }
                var tb = new StringBuffer();
                foreach (var col in model)
                {
                    tb += Environment.NewLine;
                    if (col.Null.Equals("NO"))
                    {
                        tb += string.Format("[Required]{0}", Environment.NewLine);
                    }
                    if (col.Key.Equals("PRI"))
                    {
                        tb += "[PrimaryKey]" + Environment.NewLine;
                    }
                    if (!string.IsNullOrEmpty(col.Comment))
                    {
                        tb += string.Format("[DisplayName(\"{0}\")]{1}", col.Comment, Environment.NewLine);
                    }
                    var type = col.Type;
                    if (type.Contains("("))
                    {
                        var temp = type.Split('(');
                        type = temp[0];
                        var length = temp[1].Substring(0, temp[1].LastIndexOf(")", StringComparison.Ordinal));
                        if (type.Equals("text") || type.Equals("varchar"))
                            tb += string.Format("[StringLength({0})]{1}", length, Environment.NewLine);
                    }
                    var name = col.Field.Pascalize();
                    var mappingDic = new Dictionary<string, string>
                                         {
                                             {"tinyint", "bool"},
                                             {"int", "int"},
                                             {"bigint", "long"},
                                             {"varchar", "string"},
                                             {"text", "string"},
                                             {"datetime", "DateTime"},
                                             {"decimal", "Decimal"}
                                         };
                    //未匹配的默认为string
                    var typeStr = mappingDic[type] ?? "string";
                    tb += string.Format("public {0}{1}{2}{3}{4}", typeStr, (col.Null.Equals("YES") && !typeStr.Equals("string") ? "? " : " "), name, "{get; set;}", Environment.NewLine);
                }
                return tb.ToString();

            }
        }
开发者ID:dalinhuang,项目名称:info_platform,代码行数:54,代码来源:DevelopmentActivity.cs


注:本文中的SessionFactory.FindBySql方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。