-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LoadFromCollection ordering nested table columns while filtering member info #1196
Comments
Thanks for reporting, we'll have a look at this. |
@ChristopherBrownie Just to make this clearer, can you give me the class definitions (or at least enough to replicate this issue), including the attributes, for the |
Sure thing, here's a simple version of the classes: public class Person : BaseModel
{
[Key]
public int Id { get; set; }
[ForeignKey(nameof(Residence))]
public int? ResidenceSystemID { get; set; }
[OfficeOpenXml.Attributes.EpplusNestedTableColumn(HeaderPrefix = "Residence.")]
public virtual Residence Residence { get; set; }
[Display(Name = "First Name")]
public string FirstName { get; set; }
[Display(Name = "Last Name")]
public string LastName { get; set; }
public int? Age { get; set; }
}
public class Residence : BaseModel
{
[OfficeOpenXml.Attributes.EpplusIgnore]
public virtual ICollection<Person> Residents { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zip { get; set; }
public string Type { get; set; }
}
public abstract class BaseModel
{
[Key]
public int Id { get; set; }
public DateTime? CreatedDate { get; set; }
public DateTime? LastEditDate { get; set; }
} |
@ChristopherBrownie - I had a look at this, don't know which EPPlus/.NET version you are using, so tested with the latest EPPlus 7 code base under .NET 6. From what I can see the columns are (using the classes in your previous message):
The first three are in the order as specified by the members sent in to the function. And since no other order was provided for the
[EPPlusTableColumnSortOrder(Properties = new string[] { nameof(Id), nameof(FirstName), nameof(LastName), nameof(Residence)})]
public class Person : BaseModel
{
}
[EPPlusTableColumnSortOrder(Properties = new string[] { nameof(Id), nameof(CreatedDate), nameof(LastEditDate), nameof(Address), nameof(City), nameof(Zip), nameof(State), nameof(Type)})]
public class Residence : BaseModel
{
} |
Thanks for looking into this. You are correct I am in .NET 6 with EPPlus 7.0.2. I seem to be getting inconsistent results on my end. Based on the feedback you provided for ordering properties, is the order of specified filtered members used to set the order of the columns? I assumed it was, but the wiki doesn't specify. It seems to work for me without a nested table column, but is this ordering just coincidental or an intended feature? |
The member filter can be used to specify the order without the nested class, it is a very different internal logic in EPPlus for how to build up the columns when this attribute is added. Since the members filter only works on the outermost class the sortorder will be built up using a combination of the members and any other ordering specified by attributes. My advice in the previous message is based on how it works today, when I debugged this I noticed that in this particular case (when combined with a nested property) the "reflection-order" was used. I will try to look deeper into this, ideally the order of the members should define the column order even if one of the properties is a nested class, if not possible we will update the docs/wiki. Until we have found a better solution for this, my advice is to define the sort order via attributes as described above if you are using any other attribute than |
@ChristopherBrownie I have looked into this again today and we can make this more consistent in the next version. I'm working on a solution where any members provided via the |
When specifying member info to include, it seems the order of the members specified determines the order of the columns (which is great!).
The following gives me columns
Id
,FirstName
,LastName
in that order.Now that #1052 has been fixed, adding in a
EPPlusNestedTableColumn
attribute to this produces unexpected ordering.The above produces columns in the order of
Id
,Residence.Address
,FirstName
,Residence.Id
,LastName
. The nested table columns have been scattered about while the main properties remain in the correct order.I would expect to keep all residence columns together and display them in the position specified in the member info, which in this case is after
LastName
.The text was updated successfully, but these errors were encountered: