Search code examples
c#.netentity-frameworkdomain-driven-design

new id inside domain events


I'm creating domain events so that they communicate between different contexts.

I thought of using the Id as the identifier of the entities, which in my case is of type long. My domain events are created within the entity itself, for example, in an AddItens function, I create an event.

That is where my problems begin as far as I could see in the .net Entity Framework I only have this id filled in after "add" (without committing the transaction). I'm using cqrs tbm and in my command handler when creating the entity and calling the AddItens function my event is created more with the id 0 because I haven't made any transactions with the bank yet.

When calling the entityframework's add/addasync function, my entity's id is filled in correctly, but my event that has already been created keeps the value 0.

What is the best practices for these cases?

I'm trying to use hilo for creating a sequence but this does not work because they create a sequence only if add/addasync function was called.


Solution

  • I decided to change my choice and work with UUID