Closed spudcz closed 3 years ago
Well I have found the solution ... I can't use the function Sql.Ext.ListtAgg but instead there is an extension method StringAggregate translated into LISTAGG sql function.
So the example above would be:
public class Position {
public int CompanyId { get; set; }
public string Email { get; set; }
}
public class MyDataConection : DataConnection {
public ITable<Position> Positions => GetTable<Position>();
public IQueryable<object> CompanyEmails1 => Positions
.GroupBy(p => p.CompanyId)
.Select(g => {
CompanyId = g.Key,
Emails = g.StringAggregate(",", p => p.Email).OrderBy(p => p.Email).ToValue()
});
public IQueryable<object> CompanyEmails2 =>
from p in Positions
group p by p.CompanyId into grouping
select new {
CompanyId = grouping.Key,
Emails = grouping.StringAggregate(",", x => x.Email).OrderBy(x => x.Email).ToValue()
};
}
Hi, can you please help me with Sql.Ext.ListAgg function?
I'm trying to build query with Linq2DB that would group row by CompanyId and build comma separated list of Emails:
Here is my c# model:
First query CompanyEmails1 builds this and fails (missing group by statement):
Second query CompanyEmails2 builds this and fails too:
The only examples I found were in the documentation of Linq2DB and in samples there doesn't figure GroupBy in linq query
Also in source code there are some tests with usage of function ListAgg and there doesn't figure GroupBy neither.