无法将System.String类型的值转换为OData类型[Edm.Guid Nullable = True]

时间:2016-04-13 08:14:56

标签: c# odata

当我尝试使用以下查询更新记录时,我的用户类如下所示,它给了我例外。

public class User
{
    public User();

    public Guid Id { get; set; }
    public virtual Language Language { get; set; }
    public Guid? LanguageId { get; set; }
    public virtual City City { get; set; }
    public Guid? CityId { get; set; }
}

代码

            Guid cityId = new Guid("4B1FCCA6-3E43-44BA-8516-BC693F02E9B5");

            await myClient.For<User>()
            .Filter(t => t.CityId == cityId)
            .Set(new { LanguageId = languageId  })
            .UpdateEntryAsync();

执行上述更新语句后,我获得了异常 Unable to convert value of type System.String to OData type [Edm.Guid Nullable=True] myClientSimple Odata client

1 个答案:

答案 0 :(得分:1)

显然LanguageId = languageId正在给你这个错误,因为Guid类型不同。一个是.net inbuild和一个我认为你从服务电话获得的。另外,我认为languageId这里是导致问题的字符串

如此处所定义http://www.odata.org/documentation/odata-version-2-0/overview/

Edm.Guid : Represents a 16-byte (128-bit) unique identifier value.