Asp.net mvc 3 MVC3:Guid数据类型
我有一个从数据库获取数据的项目。我对模型中的数据库字段做了一些修改,现在我得到了错误Asp.net mvc 3 MVC3:Guid数据类型,asp.net-mvc-3,guid,uniqueidentifier,Asp.net Mvc 3,Guid,Uniqueidentifier,我有一个从数据库获取数据的项目。我对模型中的数据库字段做了一些修改,现在我得到了错误 The 'XXX' property on 'YYY' could not be set to a 'Guid' value. You must set this property to a non-null value of type 'String'. XXX是类的键,在模型中定义为 公共字符串XXX{get;set;} 我的数据库中此字段的数据类型为uniqueidentifier mvc3中这种数据
The 'XXX' property on 'YYY' could not be set to a 'Guid' value. You must set this property to a non-null value of type 'String'.
XXX是类的键,在模型中定义为
公共字符串XXX{get;set;}
我的数据库中此字段的数据类型为uniqueidentifier
mvc3中这种数据类型的“等价性”是什么
编辑
我尝试将XXX的数据类型更改为
公共Guid XXX{get;set;}
但是我弄错了
The 'XXX' property on 'YYY' could not be set to a 'Guid' value. You must set this property to a non-null value of type 'String'.
“YYY”上的“UnallocatedId”属性无法设置为“Guid”值。必须将此属性设置为“String”类型的非空值
正如错误中所述,您需要使用
Guid
类型:
public Guid XXX { get; set; }
数据库中的字段是否不为空?还是空?@MartinSmith:请参见编辑。字段XXX是数据库中的主键。
System.Guid
相当于uniqueidentifier
。我认为不需要铸造。你可以查一下