0

当我尝试从表存储中读取时,出现以下异常。我在添加DateTime?属性后得到它。

例外:

The current value 'String.Empty' type is not compatible with the expected 'System.DateTime' type.

内部异常:

The string '' is not a valid AllXsd value.

我想到了以下解决方案:

  1. 我让提供者将不存在的值映射到 null
  2. 用日期更新对象(但我无法获取它?)

有没有人对如何解决这个问题有更好的想法?

堆栈跟踪:

System.InvalidOperationException: The current value 'String.Empty' type is not compatible with the expected 'System.DateTime' type. ---> System.FormatException: The string '' is not a valid AllXsd value.
   at System.Xml.Schema.XsdDateTime..ctor(String text, XsdDateTimeFlags kinds)
   at System.Xml.XmlConvert.ToDateTime(String s, XmlDateTimeSerializationMode dateTimeOption)
   at System.Data.Services.Client.ClientConvert.ChangeType(String propertyValue, Type propertyType)
   --- End of inner exception stack trace ---
   at System.Data.Services.Client.ClientConvert.ChangeType(String propertyValue, Type propertyType)
   at System.Data.Services.Client.AtomMaterializer.MaterializeDataValue(Type type, AtomContentProperty atomProperty, DataServiceContext context)
   at System.Data.Services.Client.AtomMaterializer.MaterializeDataValues(ClientType actualType, List`1 values, Boolean ignoreMissingProperties, DataServiceContext context)
   at System.Data.Services.Client.AtomMaterializer.MaterializeResolvedEntry(AtomEntry entry, Boolean includeLinks)
   at System.Data.Services.Client.AtomMaterializer.Materialize(AtomEntry entry, Type expectedEntryType, Boolean includeLinks)
   at System.Data.Services.Client.AtomMaterializer.DirectMaterializePlan(AtomMaterializer materializer, AtomEntry entry, Type expectedEntryType)
   at System.Data.Services.Client.AtomMaterializerInvoker.DirectMaterializePlan(Object materializer, Object entry, Type expectedEntryType)
   at System.Data.Services.Client.ProjectionPlan.Run(AtomMaterializer materializer, AtomEntry entry, Type expectedType)
   at System.Data.Services.Client.AtomMaterializer.Read()
   at System.Data.Services.Client.MaterializeAtom.MoveNextInternal()
   at System.Data.Services.Client.MaterializeAtom.MoveNext()
   at System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

模型

class Car : TableServiceEntity {

 public DateTime? LastUpdated { get; set; }
 public DateTime? LastUsed { get; set; }

// more properties

}

询问

 var sx = this.GetServiceContext();
 return (from x in sx.CreateQuery<Car>("Table") select x).ToList();
4

1 回答 1

0

如果有人用谷歌搜索,我找到了解决方案:

我正在使用 Azure 存储资源管理器,当我在测试时更新另一个属性时,它在其中一个实体中保存了一个空字符串而不是可以为空的日期。

于 2012-06-29T15:01:32.680 回答