0

我在 wpf 中为我的 EF 定义了波纹管类,用于 mvvm 模式:

public class ProductGroup : ViewModelBase
{

    public long ID { get; set; }

    private string _Title;
    public string Title
    {
        get { return _Title; }
        set
        {
            if (_Title != value)
            {
                _Title = value;
                this.RaisePropertyChanged("Title");
            }
        }
    }

    private byte[] _Icon;
    public byte[] Icon
    {
        get { return _Icon; }
        set
        {
            if (_Icon != value)
            {
                _Icon = value;
                this.RaisePropertyChanged("Icon");
            }
        }
    }

    private ProductGroup _Parent;
    public ProductGroup Parent
    {
        get { return _Parent; }
        set
        {
            if (_Parent != value)
            {
                _Parent = value;
                this.RaisePropertyChanged("Parent");
            }
        }
    }

    private ObservableCollection<ProductGroup> _Childs;
    public ObservableCollection<ProductGroup> Childs
    {
        get { return _Childs; }
        set
        {
            if (_Childs != value)
            {
                _Childs = value;
                this.RaisePropertyChanged("Childs");
            }
        }
    }

    private ObservableCollection<Product> _Products;
    public ObservableCollection<Product> Products
    {
        get { return _Products; }
        set
        {
            if (_Products != value)
            {
                _Products = value;
                this.RaisePropertyChanged("Products");
            }
        }
    }

}

public class Product : ViewModelBase
{
    public long ID { get; set; }

    private ProductGroup _Gorup;
    public ProductGroup Gorup
    {
        get { return _Gorup; }
        set
        {
            if (_Gorup != value)
            {
                _Gorup = value;
                this.RaisePropertyChanged("Gorup");
            }
        }
    }

    private string _Name;
    public string Name
    {
        get { return _Name; }
        set
        {
            if (_Name != value)
            {
                _Name = value;
                this.RaisePropertyChanged("Name");
            }
        }
    }

}
  • 我的定义正确吗??
  • 当我想从 ProductGroups 中删除一个项目时,会发生以下错误:

保存不为其关系公开外键属性的实体时发生错误。EntityEntries 属性将返回 null,因为无法将单个实体标识为异常源。通过在实体类型中公开外键属性,可以更轻松地在保存时处理异常。有关详细信息,请参阅 InnerException。

笔记:

  • 目标 ProductGroup 是另一个 ProductGroup 的子级

  • 目标 ProductGroup 没有 Child 和 Product

4

0 回答 0