You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been running into an issue when trying to use StringAggregate with a GroupBy clause when executing against SQL Server (2017, 2019, 2022).
When I run the equivalent of the following code:
public class ProductInfo
{
public int Id { get; set; }
public string AggregatedDescription { get; set; }
}
public class Product {
[Column]
public int Id { get; set; }
[Column]
public string Description { get; set; }
}
public class ProductService {
public ITable<Product> Products => GetTable<Product>();
public IEnumerable<ProductInfo> GetAggregatedDescriptions()
{
var productsGrouped = Products
.GroupBy(x => x.Id)
.Select(g => new ProductInfo {
Id = g.Key,
AggregatedDescription = g.StringAggregate(", ", x => x.Description)
});
return productsGrouped.ToList();
}
}
I get an exception thrown --
LinqToDB.LinqToDBException: 'You should explicitly specify selected fields for server-side GroupBy() call or add AsEnumerable() call before GroupBy() to perform client-side grouping.
Set Configuration.Linq.GuardGrouping = false to disable this check.
Additionally this guard exception can be disabled by extension GroupBy(...).DisableGuard() or using options.UseGuardGrouping(false) configuration extension.
Disabling the guard doesn't seem to help, as Linq2Db throws an exception saying StringAggregate is a serverside function. Not sure if this is a potential bug or I'm doing something wrong, I've tried several permutations including g.StringAggregate(", ", x => x.Description).ToValue() to no avail.
The text was updated successfully, but these errors were encountered:
Whoops, sorry. I was cutting a class out and messed that up. I edited the example to be fully functional now.
I tried g.StringAggregate(", ", x => x.Description).ToValue(), however when I do that I get the exception LinqToDB.Linq.LinqException: ''g.StringAggregate(", ", x => x.Description).ToValue()' cannot be converted to SQL.'
Hi,
I've been running into an issue when trying to use StringAggregate with a GroupBy clause when executing against SQL Server (2017, 2019, 2022).
When I run the equivalent of the following code:
I get an exception thrown --
Disabling the guard doesn't seem to help, as Linq2Db throws an exception saying
StringAggregate
is a serverside function. Not sure if this is a potential bug or I'm doing something wrong, I've tried several permutations includingg.StringAggregate(", ", x => x.Description).ToValue()
to no avail.The text was updated successfully, but these errors were encountered: