Found the solution with this post:
Hello dear Radzen team,
I have the same problem in one of my projects, two properties:
Property="Employee.FullName"
Property="Student.FullName"
are showing in the grid easily using expand, while causing the same AmbiguousMatchException
when exporting to Excel.
In my export function I see:
{
Filter = $@"{(string.IsNullOrEmpty(grid0.Query.Filter) ? "true" : grid0.Query.Filter)}",
OrderBy = $"{grid0.Query.OrderBy}",
Expand = "Employee,Student",
Select = string.Join(",", grid0.ColumnsCollection.Where(c => c.GetVisible()).Select(c => c.Property))
}, ....
Where it uses the "Property" name for the export, so here, where should I use "aliases/as" like what is mentioned in the linked answer ?
You should extend this to use aliases instead plain property names.
It's what I understood from the first answer, which means - if I'm not mistaken - that I have to write the field names directly, something like:
Select = "ID,Employee.ID as EmployeeID,Employee.FullName as EmployeeName,Employee.Phone as EmployeePhone,Student.FullName as StudentName,Student.Phone as StudentPhone,Course.StartDate,Course.EndDate, .... , ....... (and many others)"
But in this case, I will lose the visibility control of the columns (picking on demand), which is helpful for my clients due to the large number of columns in this grid (and most other grids of the project), where I only show few columns and let the user choose what he needs to view and export.
Oh, I feel dumb for not thinking of that!
Many thanks
And also add && c.Property != null
so it will skip any column without a property name, like the "Delete Button" column (in case it was left visible on Export).
Select = string.Join(",", grid0.ColumnsCollection
.Where(c => c.GetVisible() && c.Property != null)
.Select(c => c.Property.Contains(".") ? $"{c.Property} as {c.Property.Replace(".", "_")}" : c.Property))