Пример #1
0
        public string BulkInsertCmd <T>(List <T> items)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine($"INSERT INTO {typeof(T).Name}({BulkHelper.CommaSeparatedPropertiesNameFromType(typeof(T))})");

            items.ForEach(item =>
            {
                stringBuilder.AppendLine($"SELECT {BulkHelper.CommaSeparatedPropertiesValueFromObject(item)}{BulkHelper.CmdLineDelimiter(items, item)}");
            });

            return(stringBuilder.ToString());
        }
Пример #2
0
        public string BulkDeleteCmd <T>(List <T> items, Expression <Func <T, int> > entityPropertyName) where T : class
        {
            string targetPropertyName = BulkHelper.GetPropertyName(entityPropertyName);

            var ids = items.Select(i =>
                                   BulkHelper.PropertiesToSql(i)
                                   .Where(w => w.Name == targetPropertyName)
                                   .Select(s => s.GetValue(i))
                                   .FirstOrDefault()
                                   )
                      .ToList()
                      .Where(w => w != null)
                      .ToList();

            string cmd = default(string);

            if (ids.Count > 0)
            {
                cmd = $"DELETE FROM {typeof(T).Name} WHERE {targetPropertyName} IN ({String.Join(",", ids)});";
            }

            return(cmd);
        }