Implicit conversion from byte[] to ReadOnlyMemory<byte> #18252
-
Hi Some of our models for history reasons are stored with properties that have a public class FailedAuditImport
{
public string Id { get; set; }
public FailedTransportMessage Message { get; set; }
}
public class FailedTransportMessage
{
public string Id { get; set; }
public Dictionary<string, string> Headers { get; set; }
public ReadOnlyMemory<byte> Body { get; set; }
}
public class FailedAuditImportIndex : AbstractIndexCreationTask<FailedAuditImport>
{
public FailedAuditImportIndex()
{
Map = docs =>
from cc in docs
select new FailedAuditImport
{
Id = cc.Id,
Message = cc.Message
};
}
} now the newly ingested data comes in as |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You are looking at the code that is running on the database side. And the types you use aren't actually identical to what is compiled. In this case, if you'll look at the index, the output would be something like: In other words, it elided the actual types. In order to solve that, you can use:
With the converter being defined as:
So far, that is pure client side work, and note that this isn't efficient in terms of allocations. I assume that this part you already have and I'm including that just so we can talk in the same manner.
This would be the output of this code: Now, what would be the index output in this case? I'm not sure what is the meaning behind this, though. |
Beta Was this translation helpful? Give feedback.
-
I was planning to dig deeper there because based on my initial research it is not necessary and we probably should change that index Thanks for the rest of the answer. |
Beta Was this translation helpful? Give feedback.
You are looking at the code that is running on the database side. And the types you use aren't actually identical to what is compiled. In this case, if you'll look at the index, the output would be something like:
In other words, it elided the actual types.
Note that by default, you need to add a converter to
ReadOnlyMemory<byte>
to support proper serialization on the client side, otherwise, you'll get:In order to solve that, you can use:
Wi…