2012-05-24 64 views
3

查詢時,我有,看起來像這樣轉換異常的指標

public class FeedAnnouncementByOneLabel : Raven.Client.Indexes.AbstractIndexCreationTask<FeedPost, FeedAnnouncementByOneLabel.Result> 
{ 
    public class Result 
    { 
     public long SequentialId { get; set; } 
     public string AnnouncementId { get; set; } 
     public string Label1 { get; set; } 
     public string FeedOwner { get; set; } 
     public DateTimeOffset CreationDate { get; set; } 
    } 
    public FeedAnnouncementByOneLabel() 
    { 
     Map = announcements => from doc in announcements 
           from docLabelsItem1 in ((IEnumerable<Label>)doc.Labels).DefaultIfEmpty() 
           select new Result 
           { 
            SequentialId = doc.SequentialId, 
            AnnouncementId = doc.AnnouncementId, 
            CreationDate = doc.CreationDate, 
            FeedOwner = doc.FeedOwner, 
            Label1 = docLabelsItem1.Text 
           }; 
    } 
} 

一個索引,我詢問像這樣(簡化版本,它仍然失敗):

from c in _session.Query<FeedAnnouncementByOneLabel.Result, FeedAnnouncementByOneLabel>() 
            select c; 

我得到一個異常每次我查詢它。非常奇怪的是,這曾經工作。我不知道自從我將Raven更新到最新版本之後它是否損壞 - 或者因爲我更改了其他內容。 林相當肯定,唯一的變化是我把「FeedPost」移動到它自己的DLL(帶有各種DataContract屬性)。

任何接受者?

感謝

<Exception xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
<ExceptionType>System.InvalidCastException</ExceptionType> 
<Message> 
Unable to cast object of type 'FeedPost' to type 'Result'. 
</Message> 
<StackTrace> 
at Raven.Client.Document.InMemoryDocumentSessionOperations.ConvertToEntity[T](String id, RavenJObject documentFound, RavenJObject metadata) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\InMemoryDocumentSessionOperations.cs:line 416 
at Raven.Client.Document.InMemoryDocumentSessionOperations.TrackEntity[T](String key, RavenJObject document, RavenJObject metadata) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\InMemoryDocumentSessionOperations.cs:line 340 
at Raven.Client.Document.SessionOperations.QueryOperation.Deserialize[T](RavenJObject result) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\SessionOperations\QueryOperation.cs:line 130 
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext() 
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) 
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) 
at Raven.Client.Document.SessionOperations.QueryOperation.Complete[T]() in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\SessionOperations\QueryOperation.cs:line 114 
at Raven.Client.Document.AbstractDocumentQuery`2.GetEnumerator() in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\AbstractDocumentQuery.cs:line 603 
at Raven.Client.Linq.RavenQueryInspector`1.GetEnumerator() in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Linq\RavenQueryInspector.cs:line 98 
at System.Linq.Buffer`1..ctor(IEnumerable`1 source) 
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) 
at FeedPostsController.Get(String labels, Int32 sincePostId) in FeedPostsController.cs:line 211 
at lambda_method(Closure , Object , Object[]) 
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments) 
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.Execute(HttpControllerContext controllerContext, IDictionary`2 arguments) 
at System.Web.Http.Controllers.ApiControllerActionInvoker.<>c__DisplayClass2.<InvokeActionAsync>b__0() 
at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken) 
</StackTrace> 
</Exception> 

[更新]

好了 - 我感動FeedPost定義回是有指標的同一個DLL ...還是失敗。

回答

1

只是嘗試這樣做(https://gist.github.com/2780374),我很老的錯誤(即查詢無差錯運行)壽沒有結果

好像你正在試圖獲得所有的標籤飼料通告,然後也許這可以工作? 我刪除了annoucementId和另一個id,因爲它會妨礙聚合(按標籤),但也許我的域名是錯誤的。

​​