Exemplo n.º 1
0
        private static int getCount(String action, IEntity target, EntityInfo entityInfo, EntityPropertyInfo info, Object obj)
        {
            if (obj == null)
            {
                return(1);
            }

            String           usql;
            IDatabaseDialect dialect = entityInfo.Dialect;

            if (action.Equals("update"))
            {
                usql = String.Format("select count(Id) from {0} where Id<>{3} and {1}={2}", entityInfo.TableName, info.ColumnName, dialect.GetParameter(info.Name), target.Id);
            }
            else
            {
                usql = String.Format("select count(Id) from {0} where {1}={2}", entityInfo.TableName, info.ColumnName, dialect.GetParameter(info.Name));
            }

            logger.Info(LoggerUtil.SqlPrefix + " validate unique sql : " + usql);
            IDbCommand cmd = DataFactory.GetCommand(usql, DbContext.getConnection(entityInfo));

            DataFactory.SetParameter(cmd, info.ColumnName, obj);
            return(cvt.ToInt(cmd.ExecuteScalar()));
        }