예제 #1
0
        public static bool Exists <T>(this DbContext connInfo, object[] pkValues, string tableName = "", bool forUpdate = false)
            where T : new()
        {
            if (0 == (pkValues?.Length ?? 0))
            {
                throw new Exception("Primary keys are missing!");
            }
            Type      t         = typeof(T);
            TableInfo tableInfo = GetTableInfo(t, 0, tableName);

            if (0 == (tableInfo?.PKeys?.Count() ?? 0))
            {
                throw new ArgumentNullException("PKeys");
            }
            RequestBase param = new RequestBase();
            int         j     = 0;

            foreach (string pkName in tableInfo.PKeys)
            {
                param.Add(pkName, pkValues[j]);
                ++j;
            }
            string sql = connInfo.GetExistsSql(t, tableName);

            if (forUpdate && connInfo.SupportForUpdate)
            {
                sql += " for update";
            }
            return(connInfo.Db.ExecuteScalar <string>(sql, param, connInfo.Transaction, commandType: CommandType.Text).IsTrue());
        }
예제 #2
0
        public static bool Exists <T>(this DbContext connInfo, T record, string tableName = "", bool forUpdate = false) where T : new()
        {
            string sql = connInfo.GetExistsSql(typeof(T), tableName);

            if (forUpdate && connInfo.SupportForUpdate)
            {
                sql += " for update";
            }
            return(connInfo.Db.ExecuteScalar <string>(sql, record, connInfo.Transaction, commandType: CommandType.Text).IsTrue());
        }