Esempio n. 1
0
        internal static (string name, string columnList, string parametersList) GetInsertParameters(BaseModel entityToInsert, QueryStrategy strategy)
        {
            var type = entityToInsert.GetType();

            var name = GetTableName(type);

            var sbColumnList = new StringBuilder(null);

            var allProperties                = TypePropertiesCache(type).ToList();
            var identityProperties           = IdentityPropertiesCache(type).ToList();
            var allPropertiesExceptIndentity = allProperties.Except(identityProperties).ToList();

            var index = 0;
            var lst   = allPropertiesExceptIndentity;

            foreach (var property in lst)
            {
                sbColumnList.Append(strategy.Enclose(property.Name));
                if (index < lst.Count - 1)
                {
                    sbColumnList.Append(", ");
                }
                index++;
            }

            index = 0;
            var sbParameterList = new StringBuilder(null);

            foreach (var property in lst)
            {
                sbParameterList.Append($"@{property.Name}");
                if (index < lst.Count - 1)
                {
                    sbParameterList.Append(", ");
                }
                index++;
            }

            return(name, sbColumnList.ToString(), sbParameterList.ToString());
        }
Esempio n. 2
0
 internal QueryBuilder(IRepoQuery repoQuery, QueryStrategy strategy)
 {
     _repoQuery = repoQuery;
     _builder   = new StringBuilder();
     _strategy  = strategy;
 }