Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.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
Asp.net mvc 3 MVC3:Guid数据类型_Asp.net Mvc 3_Guid_Uniqueidentifier - Fatal编程技术网

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
。我认为不需要铸造。你可以查一下