假设我有一类叫做客户(通过实体框架自动生成)检查对象为空
CustomerID // Primary Key & Auto-increment
Name
Gender
City
现在在我的视图模型:
public Class myViewModel : INotifyPropertyChanged
{
public Customer CurrentCustomer
{
get
{
return MainViewModel.cCustomer;
}
set
{
myViewModel.cCustomer = value;
OnPropertyChanged("CurrentCustomer");
}
}
....
....
....
}
这里是我的MainViewModel
public Class MainViewModel : INotifyPropertyChanged
{
public MainViewModel()
{
cCustomer = new Customer();
}
public static Customer cCustomer { get; set; }
public void SaveChanges()
{
//Here I want to check if all the fields of cCustomer are empty
//And depending on that I want to save the cCustomer.
}
....
....
....
}
我试图通过将它们与null比较来检查cCustomer的所有字段,但是在那里我得到一个错误,指出对象引用没有设置为对象的实例。
总之,我想在保存客户时检查cCustomer是否为空。
'if(cCustomer!= null)'不起作用? – Tim
附加调试器,看看什么是空? –
cCustomer是否曾实例化或初始化? –