3

最新の RavenDB に更新した後、次のエラーが発生します。

[InvalidCastException: タイプ 'Index_Auto_2fDocuments_2fByCreationDateTimeAndPublishTimeSortByCreationDateTimePublishTime' のオブジェクトをタイプ 'Raven.Database.Linq.AbstractViewGenerator' にキャストできません。 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名前、IndexDefinition 定義) c:\Builds\RavenDB-Stable\Raven.Database\DocumentDatabase.cs:1207 Raven.Database.Queries.DynamicQueryRunner.CreateAutoIndex(String permanentIndexName, Func1 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.AbstractDocumentQuery2. c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\AbstractDocumentQuery.cs:664 の2.get_QueryResult() in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\AbstractDocumentQuery.cs:633 Raven.Client.Linq.RavenQueryProviderProcessorExecuteActualQuery() Raven.Client.Document.AbstractDocumentQuery 1. c:\Builds\RavenDB-Stable\ の ExecuteQuery() 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.List1..ctor(IEnumerable1 collection) +446 System.Linq.Enumerable.ToList(IEnumerable1 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 c:\Dev\Repos\Git\Writer\Blog\Controllers\DocumentController.cs:18 の Blog.Controllers.DocumentController.Index() lambda_method(Closure , ControllerBase , Object[] ) +79 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext、IDictionary 2 parameters) +261 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 パラメーター) +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 ステップ、ブール値および完了同期) +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 は DateTime の処理方法を変更しましたか? 誰かが解決策、または私を正しい方向に向ける記事を知っていますか.

更新 これは、データベースにクエリを実行してドキュメントを取得しようとしたときにのみ発生することがわかります。これは、空のデータベースとドキュメントを含むデータベースでテストされています。save メソッドが正常に機能することがわかります。

4

1 に答える 1

2

これは、nuget から Raven.Embedded をアンインストールして再インストールすることで修正されました。

于 2013-09-12T18:22:52.713 に答える