Transformer returns null for read only properties

21 views
Skip to first unread message

Steven Roberts

unread,
Dec 5, 2016, 10:21:10 PM12/5/16
to RavenDB - 2nd generation document database
I have this Transformer

    public class TraceabilityTransformer : AbstractTransformerCreationTask<ProjectTraceability4>
    {
        public TraceabilityTransformer()
        {
            TransformResults = traceabilities => from traceability in traceabilities
                let roots = LoadDocument<IAmTraceable>(traceability.Connections.Select(x => x.Id))
                select new ProjectTraceabilityViewModel2
                {
                    Id = traceability.ProjectId,
                    Traceables = roots.Select(r => new RelatedTraceableViewModel
                    {
                        Id = r.Id,
                        Title = r.Name,
                        DeliverableId = r.DeliverableId,
                        Group = r.Group,
                        Status = r.CurrentStatus,
                        Type = r.Type,
                        Connections = traceability.Connections
                            .Where(x => x.Id == r.Id)
                            .ToDictionary(x => x.Id, x => x.Links.ToArray())
                    }).ToArray(),
                };

        }
    }

I'm using the interface (IAmTraceable) because the objects are different.  Everything works great except for the 2 properties that are read only. CurrentStatus and Type, both of which return hardcoded values as a Get only property.  I realize there are no 'types' on the server but without the IAmTraceable how do I get to use the properties that I need?



Oren Eini (Ayende Rahien)

unread,
Dec 6, 2016, 1:22:10 AM12/6/16
to ravendb
What are the properties that you have on the _document_? And how does the trasnformer looks on the server?

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 





--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Steven Roberts

unread,
Dec 6, 2016, 6:55:19 AM12/6/16
to RavenDB - 2nd generation document database
I realized shortly after posting and going to bed that the property naturally wouldn't exist on the server because it's a readonly get that isn't serialized.  I was able to solve for 1 of the properties by using metadata, but not the second.  The issue is that the documents that implement the interface have a property called Status, but the return type for each is different.  Here is the transformer on the server side that does work

from traceability in results
select new {
traceability = traceability,
roots = this.LoadDocument(traceability.Connections.Select(x => x.Id))
} into this0
select new {
Id = this0.traceability.ProjectId,
Traceables = Enumerable.ToArray(this0.roots.Select(r => new {
r = r,
metadata = r["@metadata"]
}).Select(this00 => new {
Title = this00.r.Name,
DeliverableId = this00.r.DeliverableId,
Group = this00.r.Group,
Status = this00.r.Status.State,
Type = this00.metadata.Value<string>("Raven-Entity-Name"),
Connections = Enumerable.ToDictionary(this0.traceability.Connections.Where(x1 => x1.Id == this00.r.Id), x2 => x2.Id, x3 => x3.Links.ToArray())
}))
}

The highlighted bit is where the trouble occurs.  I had to make this modification on the server.

I had though that I could abstract the property to a common string using the interface but of course that makes no sense on the server.  I think the answer is to make the common property of the same return type (or base type)
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages