Raymond Dazo
unread,Jan 5, 2022, 12:21:48 PM1/5/22Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to RavenDB - an awesome database
Hi RavenDB Team,
Need help. I've been trying to figure this out using c#, RavenDB v4.2. But no luck.
I need to split each products based of company name. Example "product1" belongs to company "A", which should be stored to collection "ProductA", "product2" belongs to company "B" should be stored to "ProductB", and so on.
I need to have a model (c# class) that represents the document, as I would still like to have type-checking without using Dynamic or ExpandoObject.
Currently I am using BulkInsert to transfer a huge amount of products from another system to our RavenDB database.
Here is a snippet of my code:
foreach (var item in data.Results)
{
var product = new Product()
{
Name = item.Name,
Company = item.Company
}
bulkInsert.Store(cashflow);
}
I still want to be able to instantiate a model, but I've been trying to figure out how to change the Id prefix and collection at the same time.
All available conventions either deals with only one and not both, or only one has the data for the current document to check.
BulkInsert has a way to pass metadata, but I can't figure out how to get/create an instance of a metadata for a collection that may not exists yet.
In summary, is there a way to dynamically specify a prefix Id and collection name and still able to use a model class?
Example of desired output:
ProductsA/1
{
"Name": "Product1",
"@metadata": {
"@collection": "ProductsA",
"Raven-Clr-Type": "MyProject.Models.Products, MyProject"
}
}
ProductsB/1
{
"Name": "Product2",
"@metadata": {
"@collection": "ProductsB",
"Raven-Clr-Type": "MyProject.Models.Products, MyProject"
}
}
Notice that @collection is different but "
Raven-Clr-Type" type is the same.
Thank you,
Raymond Dazo