Breeze.js不支持具有TimeSpan属性的EF实体?

时间:2012-12-20 23:15:09

标签: entity-framework entity-framework-4 breeze

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

  1. 添加持续时间属性
  2. 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: 
    

3 个答案:

答案 0 :(得分:2)

在构建0.84.1中添加了TimeSpan支持。

TimeSpans在breeze客户端上表示为ISO 8601“duration”字符串。见http://en.wikipedia.org/wiki/ISO_8601

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

var query = EntityQuery.from("Contracts").where("TimeElapsed", ">", "PT4H30M");

答案 1 :(得分:1)

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

我已将此添加到我们的功能请求日志中,但请将其添加到Breeze User Voice(并投票给它:))。这有助于我们确定优秀功能请求的优先级。

答案 2 :(得分:0)

嗯......这个请求很有意义。但是你想要将它转换为javascript,字符串或自某个时间点以来的秒数......或者是否存在.NET时间跨度的标准javascript表示形式?