private string BuildVariableCommandText(T modelEntity)
        {
            StringBuilder stringBuilder = new StringBuilder(WHITE_SPACE + "SET" + WHITE_SPACE);
            Type          entityType    = modelEntity.GetType();

            PropertyInfo[] propertiesInfo = entityType.GetProperties();


            for (int i = 0; i < propertiesInfo.Length - 1; ++i)
            {
                stringBuilder.Append(propertiesInfo[i].Name + EQUALS + AttributeValueHelper.IfStringDoQuotaiton(propertiesInfo[i].GetValue(modelEntity)) + WHITE_SPACE + COMMA);
            }
            stringBuilder.Append(propertiesInfo.Last().Name + EQUALS + AttributeValueHelper.IfStringDoQuotaiton(propertiesInfo.Last().GetValue(modelEntity)) + WHITE_SPACE);
            string whereExpression = DbCommand <T> .BuildWhereExpression(modelEntity, modelEntity.GetPrimaryKeyPropertyNames(), false);

            return(stringBuilder.Append(whereExpression).ToString());
        }
        private string BuildVariableCommandText(string tableName, T modelEntity)
        {
            StringBuilder stringBuilderColumnNames        = new StringBuilder(WHITE_SPACE + OPENNING_BRACKET + WHITE_SPACE);
            StringBuilder stringBuilderCorespondingValues = new StringBuilder(WHITE_SPACE + OPENNING_BRACKET + WHITE_SPACE);
            Type          entityType = modelEntity.GetType();

            PropertyInfo[] propertiesInfo = entityType.GetProperties();
            propertiesInfo = propertiesInfo.Where(x => x.Name.CompareTo(modelEntity.GetPrimaryKeyPropertyNames().First()) != 0).ToArray();
            for (int i = 0; i < propertiesInfo.Length - 1; ++i)
            {
                stringBuilderColumnNames.Append(propertiesInfo[i].Name + COMMA);
                stringBuilderCorespondingValues.Append(AttributeValueHelper.IfStringDoQuotaiton(propertiesInfo[i].GetValue(modelEntity)) + COMMA);
            }
            stringBuilderColumnNames.Append(propertiesInfo.Last().Name + CLOSING_BRACKET);
            stringBuilderCorespondingValues.Append(AttributeValueHelper.IfStringDoQuotaiton(propertiesInfo.Last().GetValue(modelEntity)) + CLOSING_BRACKET);
            stringBuilderColumnNames.Append(" VALUES " + stringBuilderCorespondingValues.ToString());
            return(stringBuilderColumnNames.ToString());
        }
Exemplo n.º 3
0
        protected static string BuildWhereExpression(T entity, string[] attributesName, bool?deleted)
        {
            StringBuilder stringBuilder  = new StringBuilder(" WHERE ");
            Type          entityType     = entity.GetType();
            string        lastPrimaryKey = attributesName.Last();

            attributesName = attributesName.TakeWhile(x => x != lastPrimaryKey).ToArray();
            foreach (string key in attributesName)
            {
                stringBuilder.Append(WHITE_SPACE + key + EQUALS_SIGN + AttributeValueHelper.IfStringDoQuotaiton(entityType.GetProperty(key).GetValue(entity)) + " AND");
            }
            stringBuilder.Append(WHITE_SPACE + lastPrimaryKey + EQUALS_SIGN + AttributeValueHelper.IfStringDoQuotaiton(entityType.GetProperty(lastPrimaryKey).GetValue(entity)));
            if (deleted != null)
            {
                stringBuilder.Append(" AND Deleted = " + Convert.ToInt32(deleted));
            }
            return(stringBuilder.ToString());
        }