以下のようなクラス階層があり、NHibernate を介して DB からデータをロードします。オートマッピングを使用しています。
public class Unit
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
}
public class Value
{
public virtual int Id { get; set; }
public virtual double Quantity { get; private set; }
}
public class DirectQuantity : Value
{
}
public class DependentQuantity : Value
{
private double _getValue()
{
throw new NotImplementedException();
}
public override double Quantity
{
get
{
return _getValue();
}
}
}
public class MainCategory
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual string Notes { get; set; }
}
public class ItemTemplate
{
public virtual int Id { get; set; }
public virtual string Description { get; set; }
public virtual Unit Unit { get; set; }
public virtual MainCategory Category { get; set; }
public virtual List<ItemTemplate> Children { get; set; }
}
public class Item
{
public virtual int Id { get; set; }
public virtual string Note { get; set; }
public virtual Value Quantity { get; set; }
public virtual ItemTemplate Template { get; set; }
public virtual List<Item> Children { get; set; }
}
public class BSR
{
public virtual int Id { get; set; }
public virtual string Description { get; set; }
public virtual List<MainCategory> Categories { get; set; }
}
私はDTOを次のように書きました:
public class UnitDto : INotifyPropertyChanged
{
public int Id { get; set; }
private string _name;
public string Name
{
get { return _name; }
set
{
_name = value;
PropertyChanged(this, new PropertyChangedEventArgs("Name"));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
public class ValueDto : INotifyPropertyChanged
{
public int Id { get; set; }
public double Quantity
{
get { return _Quantity; }
set
{
if (_Quantity != value)
{
_Quantity = value;
OnPropertyChanged(QuantityPropertyName);
}
}
}
private void OnPropertyChanged(string PropertyName)
{
PropertyChanged(this, new PropertyChangedEventArgs(PropertyName));
//throw new NotImplementedException();
}
private double _Quantity;
public const string QuantityPropertyName = "Quantity";
public event PropertyChangedEventHandler PropertyChanged;
}
public class DirectQuantityDto : ValueDto
{
}
public class DependentQuantityDto : ValueDto
{
}
public class MainCategoryDto : INotifyPropertyChanged
{
public int Id { get; set; }
public string Name
{
get { return _Name; }
set
{
if (_Name != value)
{
_Name = value;
OnPropertyChanged(NamePropertyName);
}
}
}
private string _Name;
public const string NamePropertyName = "Name";
public string Notes
{
get { return _Notes; }
set
{
if (_Notes != value)
{
_Notes = value;
OnPropertyChanged(NotesPropertyName);
}
}
}
private string _Notes;
public const string NotesPropertyName = "Notes";
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string PropertyName)
{
PropertyChanged(this, new PropertyChangedEventArgs(PropertyName));
//throw new NotImplementedException();
}
}
public class ItemTemplateDto :INotifyPropertyChanged
{
public int Id { get; set; }
public string Description
{
get { return _Description; }
set
{
if (_Description != value)
{
_Description = value;
OnPropertyChanged(DescriptionPropertyName);
}
}
}
private string _Description;
public const string DescriptionPropertyName = "Description";
public int? UnitID
{
get { return _UnitID; }
set
{
if (_UnitID != value)
{
_UnitID = value;
OnPropertyChanged(UnitIDPropertyName);
}
}
}
private int? _UnitID;
public const string UnitIDPropertyName = "UnitID";
public int? MainCategoryId
{
get { return _MainCategoryId; }
set
{
if (_MainCategoryId != value)
{
_MainCategoryId = value;
OnPropertyChanged(MainCategoryIdPropertyName);
}
}
}
private int? _MainCategoryId;
public const string MainCategoryIdPropertyName = "MainCategoryId";
public ObservableCollection<int> ChildItemIds { get; set; }
private void OnPropertyChanged(string PropertyName)
{
PropertyChanged(this, new PropertyChangedEventArgs(PropertyName));
//throw new NotImplementedException();
}
public event PropertyChangedEventHandler PropertyChanged;
}
public class ItemDto : INotifyPropertyChanged
{
public virtual int Id { get; set; }
public string Note
{
get { return _Note; }
set
{
if (_Note != value)
{
_Note = value;
OnPropertyChanged(NotePropertyName);
}
}
}
private string _Note;
public const string NotePropertyName = "Note";
public int? QuantityId
{
get { return _QuantityId; }
set
{
if (_QuantityId != value)
{
_QuantityId = value;
OnPropertyChanged(QuantityIdPropertyName);
}
}
}
private int? _QuantityId;
public const string QuantityIdPropertyName = "QuantityId";
public int? ItemTemplateId
{
get { return _ItemTemplateId; }
set
{
if (_ItemTemplateId != value)
{
_ItemTemplateId = value;
OnPropertyChanged(ItemTemplateIdPropertyName);
}
}
}
private int? _ItemTemplateId;
public const string ItemTemplateIdPropertyName = "ItemTemplateId";
public ObservableCollection<int> ChildItemIds { get; set; }
//public virtual string Note { get; set; }
//public virtual ValueDto Quantity { get; set; }
//public virtual ItemTemplateDto Template { get; set; }
//public virtual List<ItemDto> Children { get; set; }
private void OnPropertyChanged(string PropertyName)
{
PropertyChanged(this, new PropertyChangedEventArgs(PropertyName));
//throw new NotImplementedException();
}
public event PropertyChangedEventHandler PropertyChanged;
}
public class BSRDto : INotifyPropertyChanged
{
public int Id { get; set; }
public string Name
{
get { return _Name; }
set
{
if (_Name != value)
{
_Name = value;
OnPropertyChanged(NamePropertyName);
}
}
}
private string _Name;
public const string NamePropertyName = "Name";
public string Description
{
get { return _Description; }
set
{
if (_Description != value)
{
_Description = value;
OnPropertyChanged(DescriptionPropertyName);
}
}
}
private string _Description;
public const string DescriptionPropertyName = "Description";
public ObservableCollection<int> CategoryIds { get; set; }
public List<MainCategoryDto> Categories { get; set; }
private void OnPropertyChanged(string PropertyName)
{
PropertyChanged(this, new PropertyChangedEventArgs(PropertyName));
//throw new NotImplementedException();
}
public event PropertyChangedEventHandler PropertyChanged;
}
私の問題は、ID でそれらのオブジェクトを参照せずに、UI でオブジェクトの関係を表示するにはどうすればよいですか? 私はそれを行う方法を考えることができますが、それには多くのコーディングが必要になると思います. たとえば、UI で を に割り当て、複数のItemTemplateDto
を子として に割り当てることができる必要があります。人々がこれについて行く標準的な方法はありますか?ItemDto
ItemDto
ItemDto