Beispiel #1
0
        public string BuildInsert()
        {
            StringBuilder sbSql            = new StringBuilder();
            var           insertColumns    = _tableMapping.GetInsertColumns();
            var           lsCoumnNames     = new List <string>();
            var           lsParameterNames = new List <string>();

            if (insertColumns.Count < 1)
            {
                throw new EntityException("实体没有对应要插入到数据的属性!");
            }

            foreach (var col in insertColumns)
            {
                lsCoumnNames.Add(col.ColumnName);
                lsParameterNames.Add(string.Format("#{0}#", col.PropertyName));
            }

            sbSql.AppendFormat("Insert into {0}({1}) values({2})",
                               _tableMapping.TableName,
                               string.Join(",", lsCoumnNames.ToArray()),
                               string.Join(",", lsParameterNames.ToArray())
                               );

            return(sbSql.ToString());
        }