【发布时间】:2012-11-29 13:09:53
【问题描述】:
在我的数据库表中,我有一列可以包含 Guid,但也可以是 NULL。
在我的 Viewmodel 中,此字段配置为 Guid 并绑定到我的 DataGrid。
当我清除 DataGrid 中的字段并因此将值设置为 null 时,我收到错误“无法识别的 Guid 格式”。这是正确的,因为 guid 不能为空。
但是如何将其显示为 null 或至少将其作为 NULL 传递给数据库?
XAML 绑定:
<DataGridTextColumn Binding="{Binding AttributeTypeValueId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Header="AttributeTypeValueId" />
还有我在模型中的属性:
private Guid _attributeTypeValueId;
public Guid AttributeTypeValueId
{
get
{
return _attributeTypeValueId;
}
set
{
if (value != _attributeTypeValueId)
{
_attributeTypeValueId = value;
RaisePropertyChanged("AttributeTypeValueId");
}
}
}
知道我该怎么做吗?
谢谢!
【问题讨论】:
-
尝试将其设置为 Guid.Empty
-
或者尽可能使用 Nullable