Elfocrash / Cosmonaut

🌐 A supercharged Azure CosmosDB .NET SDK with ORM support
https://cosmonaut.readthedocs.io
MIT License
342 stars 44 forks source link

Bulk Executor and Cosmonaut property attributes #86

Closed andremaree closed 5 years ago

andremaree commented 5 years ago

I am trying to use BulkExecutor and Cosmonaut. So I separated the bulk methods into its own class library and then I reference the dll of the project with BulkExecuter in it from the project that has Cosmonaut in. I want to use the same model/poco classes in both projects and pass a list to the project with BulkExecuter in it. It is all working except for 1 small thing - I ran into a problem because of the Cosmonaut property attributes [CosmosCollection("myName")] and [CosmosPartitionKey]. I can set the [CosmosCollection("myName")] by using the overriddenCollectionNameparameter. But there is no other way to set [CosmosPartitionKey].

Please add a way to set [CosmosPartitionKey] in a way that is not a property attribute.

Elfocrash commented 5 years ago

Can't you specify the partition key at the RequestOptions level?

andremaree commented 5 years ago

Can't you specify the partition key at the RequestOptions level?

Yes that I can do for queries, but Cosmonaut creates the collections and then there is no partitionkey set when the collection is created. I am not sure if there are any other impact by not being able to set [CosmosPartitionKey] ?

"4.1.3 [CosmosPartitionKey] This is a parameterless attribute. It is used to decorate the property that represents the partition key definition of yourcollection. public class Book{ [CosmosPartitionKey] public string Name {get;set; }

In this case I have a partition key definition in my collection named/Name.By decorating theNameproperty with the CosmosPartitionKey attribute I enable Cosmonaut to do a lot ofbehind the scenes operation optimisation where it will set the partition key value for you if present, speeding up theoperation and making it more cost efficient."

andremaree commented 5 years ago

If cosmonaut can be used without the property attributes then it becomes easy to have separate projects - 1 using cosmonaut and 1 using bulkexecutor. From the project using cosmonaut I am able to reference the project with bulkexecutor in it and call it. This is working and is an easy option as a way to use cosmonaut and bulkexecutor together.

Elfocrash commented 5 years ago

You can disable the auto-creation of cosmonaut on startup in the CosmosStoreSettings object.

I still think that to be able to specify a partition key property without the attribute is a good idea so i will implement like this at some point, but probably not in the next month or so.

I'm open to implementation ideas or pull requests. The way I see it, you would need a Func that points towards the property you wanna use as your partition key when you initialize the CosmosStore.

andremaree commented 5 years ago

Thanks, yes I will disable the auto-creation as suggested and do the collection creation within the project containing bulkexecutor using the normal .NET SDK.