dataobjects-net icon indicating copy to clipboard operation
dataobjects-net copied to clipboard

Allow fields of type EntitySet<T> in a Structure

Open ondrejtucny opened this issue 3 years ago • 1 comments

Currently, associations are not supported in structures. Consider the following example showing how this could be useful:

[HierarchyRoot]
public class Config : Entity
{   
    [Field, Key]
    public int Id { get; set; }
}

[HierarchyRoot]
public class Settings : Entity
{    
    [Field, Key]
    public int Id { get; set; }
}

public class Tracker<T> : Structure
{
    [Field, Association]
    public EntitySet<T> History { get; set; }
    [Field, Association]
    public EntitySet<T> Current { get; set; }
    [Field, Association]
    public EntitySet<T> Future { get; set; }
}

[HierarchyRoot]
public class Container : Entity
{
    [Field, Key]
    public int Id { get; set;} 
    [Field]
    public Tracker<Config> Configuration { get; set; }
    [Field]
    public Tracker<Setting> Settings { get; set; }
}

I am tracking the history of certain items within some container entity. These items are linked to the container via a set of associations, which determine whether it's a currently valid, future, or historical item. Further, I can have multiple unrelated types of items history-tracked this way within a single container entity. By using a Structure I am able to design a generic, reusable solution.

Currently, to achieve at least a partial reusability of the pattern, I have to use an interface instead of a Structure descendant, and use an explicit implementation in the container object, so that I am able to support multiple unrelated types of items, like in the example above. This is less convenient and misuses interface implementations where Structure-based composition would be more appropriate

ondrejtucny avatar Jul 22 '21 10:07 ondrejtucny