Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 基于实体框架的MVVM验证_C#_Wpf_Entity Framework_Mvvm - Fatal编程技术网

C# 基于实体框架的MVVM验证

C# 基于实体框架的MVVM验证,c#,wpf,entity-framework,mvvm,C#,Wpf,Entity Framework,Mvvm,我目前正在从事一个使用MVVM和实体框架代码优先模型的项目。因此,我在模型类中实现了IDataErrorInfo和INotifyPropertyChanged。现在,在我的viewmodel中,我实现了一个SaveCommand和一个CanSave boolean方法,我的问题是如何为整个实体而不是单个属性生成canexecutechanged?因为我的属性已经在模型中实现了InotifyPropertyChanged 这是我的模型课 public class Guest:Validatabl

我目前正在从事一个使用MVVM和实体框架代码优先模型的项目。因此,我在模型类中实现了IDataErrorInfo和INotifyPropertyChanged。现在,在我的viewmodel中,我实现了一个SaveCommand和一个CanSave boolean方法,我的问题是如何为整个实体而不是单个属性生成canexecutechanged?因为我的属性已经在模型中实现了InotifyPropertyChanged

这是我的模型课

 public class Guest:ValidatableBindableClass
{
    //my properties here
    //implement InotifyPropertyChanged and IDataErrorInfo
}
这是我的ViewModelClass:

 public class AddEditGuestViewModel:BindableClass
{
    private Hospede guest;
    public RelayCommand SaveCommand  { get; set; }
    private readonly Hmsdb.HMS context = new Hmsdb.HMS();

    public Hospede Guest
    {
        get { return guest; }
        set { SetProperty(ref guest, value, propertyName: "Guest"); }
    }

    private void OnSave()
    {

        context.Hospedes.Add(Guest);
        context.SaveChanges();
    }

    private bool CanSave()
    {
        return context.Entry(Guest)
            .GetValidationResult().IsValid;
    }
}

通过将
null
string.Empty
传递给
PropertyChangedEventArgs
的构造函数,可以引发所有属性的
PropertyChanged
事件:

PropertyChanged(this, new PropertyChangedEventArgs(null));

不过,您需要调用每个
RelayCommand
raisecannexecutechanged()
方法。

不要发布代码图像。将相关代码复制到问题中并相应设置格式。仅发布图像会降低问题的可搜索性。根据命令的实现,调用
CommandManager.invalidateRequestSuggested()
可能就足够了。但这非常无效:。实体似乎只有一个命令。我的模型类已经为每个属性实现了propertychanged事件,问题是既然我绑定的是guest实体而不是Gues.SomeProperty,我如何才能在viewmodel类上执行changed?感谢您的重播…提升CanExecuteChanged from where?@mm8 from ViewModel