diff --git a/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs b/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs index 1e15f1a52..753de9030 100644 --- a/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs +++ b/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs @@ -525,9 +525,11 @@ public ISelect WithSql(string sql, object parms = null) } public ISelect WithMemory(IEnumerable source) { - var sb = new StringBuilder(); + var list = source?.Select(a => (object)a).ToList(); + if (list.Any() != true) throw new Exception(CoreStrings.Cannot_Be_NULL_Name(nameof(source))); + var sb = new StringBuilder(); (_orm.InsertOrUpdate().AsType(_tables[0].Table.Type) as InsertOrUpdateProvider) - .WriteSourceSelectUnionAll(source.Select(a => (object)a).ToList(), sb, _params); + .WriteSourceSelectUnionAll(list, sb, _params); try { return WithSql(sb.ToString()); } finally { sb.Clear(); }