2

在将 TimeSpan 属性添加到 DocCode 项目中的 Employee 实体后,我收到了 NotSupportedException。所以我知道它不受支持,但是......是否有计划进行转换或克服这个问题的方法。我们在实体中广泛使用 TimeSpan,有没有办法支持 TimeSpan 或计划?

  1. 添加了 Duration 属性
public class Employee
{
    ...
    public DateTime? HireDate { get; set; }

    public TimeSpan? Duration { get; set; }

    [MaxLength(60)]
    public string Address { get; set; }
    ...
}

当在运行单元测试的 NorthwindController 上调用 MetaData() 方法时,它会失败:

System.NotSupportedException was unhandled by user code
HResult=-2146233067
Message=There is no store type corresponding to the EDM type 'Edm.Time(Nullable=True)' of primitive type 'Time'.
Source=System.Data.SqlServerCe.Entity
StackTrace:
   at System.Data.SqlServerCe.SqlCeProviderManifest.GetStoreType(TypeUsage edmType)
   at System.Data.Entity.ModelConfiguration.Edm.Services.StructuralTypeMappingGenerator.MapTableColumn(EdmProperty property, DbTableColumnMetadata tableColumnMetadata, Boolean isInstancePropertyOnDerivedType, Boolean isKeyProperty)
   at System.Data.Entity.ModelConfiguration.Edm.Services.PropertyMappingGenerator.Generate(EdmEntityType entityType, IEnumerable`1 properties, DbEntitySetMapping entitySetMapping, DbEntityTypeMappingFragment entityTypeMappingFragment, IList`1 propertyPath, Boolean createNewColumn)
   at System.Data.Entity.ModelConfiguration.Edm.Services.EntityTypeMappingGenerator.Generate(EdmEntityType entityType, DbDatabaseMapping databaseMapping)
   at System.Data.Entity.ModelConfiguration.Edm.Services.DatabaseMappingGenerator.GenerateEntityTypes(EdmModel model, DbDatabaseMapping databaseMapping)
   at System.Data.Entity.ModelConfiguration.Edm.Services.DatabaseMappingGenerator.Generate(EdmModel model)
   at System.Data.Entity.ModelConfiguration.Edm.EdmModelExtensions.GenerateDatabaseMapping(EdmModel model, DbProviderManifest providerManifest)
   at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
   at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
   at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
   at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
   at System.Data.Entity.Internal.InternalContext.Initialize()
   at System.Data.Entity.Internal.InternalContext.ForceOSpaceLoadingForKnownEntityTypes()
   at System.Data.Entity.DbContext.System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext()
   at Breeze.WebApi.EFContextProvider`1.GetCsdlFromObjectContext(Object context)
   at Breeze.WebApi.EFContextProvider`1.GetCsdlFromDbContext(Object context)
   at Breeze.WebApi.EFContextProvider`1.BuildJsonMetadata()
   at Breeze.WebApi.ContextProvider.Metadata()
   at DocCode.Controllers.NorthwindController.Metadata() in c:\Users\anwalker\Downloads\breeze-runtime-plus-0.78.2\Samples\DocCode\DocCode\Controllers\NorthwindController.cs:line 20
   at lambda_method(Closure , Object , Object[] )
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.<ExecuteAsync>b__4()
   at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)
InnerException: 
4

3 回答 3

2

在 0.84.1 版本中添加了 TimeSpan 支持。

TimeSpan 在微风客户端上表示为 ISO 8601“持续时间”字符串。见http://en.wikipedia.org/wiki/ISO_8601

完整的查询支持包括过滤和返回 TimeSpan/Duration 属性的能力。IE

var query = EntityQuery.from("Contracts").where("TimeElapsed", ">", "PT4H30M");
于 2013-01-09T18:02:24.740 回答
1

好的,经过一些研究,使用 ISO8601 'duration' 标准将 .NET 时间跨度序列化到 javascript 客户端是有意义的,该标准将天、小时、分钟和秒的时间跨度表示为格式化字符串,例如:“PnnnDTnnHnnMnn .nnnS”。显然,您将需要客户端上的 javascript 库来解释和使用它。这能满足您的需求吗?

我已将此添加到我们的功能请求日志中,但也请将其添加到 Breeze用户语音中(并为它投票:))。这有助于我们优先处理未完成的功能请求。

于 2012-12-21T00:41:54.003 回答
0

嗯..这个请求是有道理的。但是,您希望它在 javascript 中转换成什么,一个字符串或自某个时间点以来的秒数或......。.NET 时间跨度是否有标准的 javascript 表示?

于 2012-12-20T23:50:17.990 回答