更新到 2.5.5.2700 后出现 RavenDB 日期时间错误

本文关键字:日期 RavenDB 时间 错误 2700 更新 | 更新日期: 2023-09-27 18:30:39

更新到最新的RavenDB后,我收到此错误:

[InvalidCastException:无法将类型为"Index_Auto_2fDocuments_2fByCreationDateTimeAndPublishTimeSortByCreationDateTimePublishTime"的对象强制转换为类型"Raven.Database.Linq.AbstractViewGenerator"。 Raven.Database.Linq.DynamicViewCompiler.GenerateInstance() in c:''Builds''RavenDB-Stable''Raven.Database''Linq''DynamicViewCompiler.cs:598 Raven.Database.Storage.IndexDefinitionStorage.AddAndCompileIndex(IndexDefinition indexDefinition) in c:''Builds''RavenDB-Stable''Raven.Database''Storage''IndexDefinitionStorage.cs:233 Raven.Database.DocumentDatabase.PutIndex(String name, IndexDefinition definition) in c:''Builds''RavenDB-Stable''Raven.Database''DocumentDatabase.cs:1207 Raven.Database.Queries.DynamicQueryRunner.CreateAutoIndex(String permanentIndexName, Func 1 createDefinition) in c:'Builds'RavenDB-Stable'Raven.Database'Queries'DynamicQueryRunner.cs:170 Raven.Database.Queries.DynamicQueryRunner.GetAppropriateIndexToQuery(String entityName, IndexQuery query, DynamicQueryMapping map) in c:'Builds'RavenDB-Stable'Raven.Database'Queries'DynamicQueryRunner.cs:158 Raven.Database.Queries.DynamicQueryRunner.ExecuteDynamicQuery(String entityName, IndexQuery query) in c:'Builds'RavenDB-Stable'Raven.Database'Queries'DynamicQueryRunner.cs:32 Raven.Client.Embedded.EmbeddedDatabaseCommands.Query(String index, IndexQuery query, String[] includes, Boolean metadataOnly, Boolean indexEntriesOnly) in c:'Builds'RavenDB-Stable'Raven.Client.Embedded'EmbeddedDatabaseCommands.cs:481 Raven.Client.Document.AbstractDocumentQuery 2.ExecuteActualQuery() in c:''Builds''RavenDB-Stable''Raven.Client.Lightweight''Document''AbstractDocumentQuery.cs:664 Raven.Client.Document.AbstractDocumentQuery 2.get_QueryResult() in c:'Builds'RavenDB-Stable'Raven.Client.Lightweight'Document'AbstractDocumentQuery.cs:633 Raven.Client.Linq.RavenQueryProviderProcessor 1.ExecuteQuery() in c:''Builds''RavenDB-Stable''Raven.Client.Lightweight''Linq''RavenQueryProviderProcessor.cs:1499 Raven.Client.Linq.RavenQueryInspector 1.GetEnumerator() in c:'Builds'RavenDB-Stable'Raven.Client.Lightweight'Linq'RavenQueryInspector.cs:105 System.Collections.Generic.List 1..ctor(IEnumerable 1 collection) +446 System.Linq.Enumerable.ToList(IEnumerable 1 source) +80 Kernel.DocumentRavenProvider.GetDocuments(Int32 count) in c:''Dev''Repos''Git''Writer''Kernel''DocumentRavenProvider.cs:85 Kernel.DocumentManager.GetDocuments(Int32 count) in c:''Dev''Repos''Git''Writer''Kernel''DocumentManager.cs:46 Blog.Controllers.DocumentController.Index() in c:''Dev''Repos''Git''Writer''Blog''Controllers''DocumentControllers.cs:18 lambda_method(闭包、控制器库、对象[] ) +79 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary 2 parameters) +261 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary 2 个参数) +39 System.Web.Mvc.Async.<>c_DisplayClass42.b_41() +34 System.Web.Mvc.Async.<>c_DisplayClass39.b_33() +124 System.Web.Mvc.Async.<>c_DisplayClass4f.b_49() +838923 System.Web.Mvc.Async.<>c_DisplayClass37.b_36(IAsyncResult asyncResult) +15 System.Web.Mvc.Async.<>c_DisplayClass2a.b_20() +33 System.Web.Mvc.Async.<>c_DisplayClass25.b_22(IAsyncResult asyncResult) +839508 System.Web.Mvc.<>c_DisplayClass1d.b_18(IAsyncResult asyncResult) +28 System.Web.Mvc.Async.<>c_DisplayClass4.b_3(IAsyncResult ar) +15 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +65 System.Web.Mvc.Async.<>c_DisplayClass4.b_3(IAsyncResult ar) +15 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +51 System.Web.Mvc.<>c_DisplayClass8.b_3(IAsyncResult asyncResult) +42 System.Web.Mvc.Async.<>c_DisplayClass4.b_3(IAsyncResult ar) +15 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +51 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completeSyncally) +288

执行此查询时

documents = session.Query<Model.Document>().Where(d => d.PublishTime <= DateTime.Now)
.OrderByDescending(document=>document.CreationDateTime).Take(count)

我正在运行嵌入式数据库,并且已尝试

  1. 删除数据库并重新启动 asp.net 应用程序。同样的错误
  2. 向数据库添加内容,然后重新启动并加载 asp.net 应用程序。同样的错误

在更新之前,非常正常。我有很多单元测试,我针对内存中的 Raven 数据库进行测试。在这里保存和检索工作正常,所以也许它与正在解析的 json 有关?

我有这个控制器调用底层 RavenDB 保存逻辑:

// POST api/document
        public async System.Threading.Tasks.Task<Model.Document> Post([FromBody]Model.Document document)
        {
            var savedDocument = await _documentManager.Save(document);
            var hubConnection = new Microsoft.AspNet.SignalR.Client.Hubs.HubConnection(BaseSiteUrl);
            var hub = hubConnection.CreateHubProxy("DocumentHub");
            hubConnection.Start().Wait();
            hub.Invoke("NewArticle", savedDocument.Id).Wait();
            return document;
        }

我的模型看起来像这样

    public class Document
    {
        public int Id { get; set; }
        public string Headline { get; set; }
        public string Text { get; set; }
        public DateTime CreationDateTime { get; set; }
        public DateTime PublishTime { get; set; }
        public HashSet<string> Tags { get; private set; }
        public int CategoryId { get; set; }
        [Raven.Imports.Newtonsoft.Json.JsonIgnore]
        public Model.Category Category { get; private set; }
        public Document()
        {
            CreationDateTime = DateTime.Now;
            Tags = new HashSet<string>();
        }
        public Document(string headline, string text, DateTime creationTime, DateTime publishTime)
        {
            Headline = headline;
            Text = text;
            CreationDateTime = creationTime;
            PublishTime = publishTime;
            Tags = new HashSet<string>();
        }
        public string GetCategoryName()
        {
            string name = String.Empty;
            if (this.Category != null)
            {
                name = this.Category.Name;
            }
            return name;
        }
        public void SetCategory(Model.Category category)
        {
            if (category != null)
            {
                this.Category = category;
                this.CategoryId = category.Id;
            }
        }
        public string GetTeaser()
        {
            string teaser = Text;
            if (Text.Count() > 250)
                teaser = Text.Substring(0, 250) + " ...";
            return teaser;
        }
        public string GetCommaSeperatedTagsString()
        {
            var tags = new StringBuilder();
            int i = 0;
            foreach (string tag in Tags)
            {
                if (!String.IsNullOrEmpty(tag))
                {
                    tags.Append(tag);
                    if (i < Tags.Count - 1)
                    {
                        tags.Append(",");
                    }
                }
                i++;
            }
            return tags.ToString();
        }
        public string GetSpaceSeperatedTagsString()
        {
            var tags = new StringBuilder();
            int i = 0;
            foreach (string tag in Tags)
            {
                if (!String.IsNullOrEmpty(tag))
                {
                    tags.Append(tag);
                    if (i < Tags.Count - 1)
                    {
                        tags.Append(" ");
                    }
                }
                i++;
            }
            return tags.ToString();
        }
        public void AddTagsString(string tagsString)
        {
            string[] tagsSplitted = tagsString.Split(',');
            foreach (var tag in tagsSplitted)
            {
                if (!String.IsNullOrEmpty(tag))
                {
                    Tags.Add(tag);
                }
            }
        }
        public string GetTimeString()
        {
            System.TimeSpan span = DateTime.Now.Subtract(this.CreationDateTime);
            string time = "lige udgivet";
            if (span.Days > 0)
            {
                if (span.Days > 1)
                    time = span.Days + " dage siden";
                else
                    time = "en dag siden";
            }
            else if (span.Hours > 0)
            {
                if (span.Hours > 1)
                    time = span.Hours + " timer siden";
                else
                    time = "en time siden";
            }
            else if (span.Minutes > 0)
            {
                if (span.Minutes > 1)
                    time = span.Minutes + " minutter siden.";
                else
                    time = "et minut siden.";
            }
            else if (span.Seconds > 0)
            {
                time = "lige udgivet";
            }
            else if (span.Milliseconds > 0)
            {
                time = "lige udgivet";
            }
            return time;
        }
    }
public class Category
            {
                public string Name { get; set; }
                public int Id { get; set; }
            }

但是,如果我中断上面的控制器方法,则 json 转换得很好。这里没有错误。

RavenDB 是否改变了处理日期时间的方式?有谁知道一个解决方案,或者一篇能为我指明正确方向的文章。

更新我可以看到这仅在我尝试查询数据库并获取文档时发生。这是在空数据库和包含文档的数据库上测试的。我可以看到保存方法工作得很好。

更新到 2.5.5.2700 后出现 RavenDB 日期时间错误

这是通过从nuget卸载Raven.Embedded 并重新安装来修复的。