0

I have an object that will populate a grid with the ability to delete via a check box. The problem is that the objects are Grouped by a few properties which are common between them when they are created. For example I have the object

public class GroupedObject
{
    Name { get; set; }
    Level { get; set; }
    Assignment { get; set; }
    AssignmentDate {get; set; }
}

in this example when I save GroupedObjects from the gui, I have multiple objects with the Name property set differently, but Can assign them the same Level, Assignment, and AssignmentDate . So those three properties make the batch unique. I was wondering what the best way to create a unique identifier that groups those three pieces of information. I was thinking of something along the lines of

public class GroupedObject
{
    ....
    public int BatchId
    {
        var batchString = string.format("{0}{1}{2}", Level, Assignment, AssignmentDate);
        return batchString.GetHashCode();
    }
}

This way on the grid I have a way of having something rendered in the background so that when I select one item in the group, the "batch of items" is selected.

Is there an alternate/standard way of handling something like this or is it up to the implementer.

indigo0086
  • 431
  • 6
  • 13

1 Answers1

1

As far as I know there is no standard way of doing what you want, so pretty much up to the implemnter.

The only issue I have with your implementation is the creation of a string - you could probably do better by getting the hash codes of all members that are part of the composite ID and generating a different hash code from them. See this post for ideas.

Note:

If performance is an issue for you (large amounts of data bound to a grid), you should test different algorithms to see what works best for your situation.

Community
  • 1
  • 1
Oded
  • 489,969
  • 99
  • 883
  • 1,009