Generation of ID in Entity Framework’s IdentityUser

This is a personal reminder that default IdentityUser and its friends (like IdentityRole) generate the ID value in its constructor. These classes extend the behavior of the generic classes (IdentityUser implements IdentityUser<TKey, …> with IdentityUser<string, …>). If you happen to use your own class that inherits from them, you’ll be responsible for generating that ID. Otherwise, you’ll get an error like the following: System.Data.SqlClient.SqlException: Cannot insert the value NULL into column ‘Id’ table ‘dbo.AspNetUsers’; column does not allow nulls. INSERT fails. The statement has been terminated. IdentityUser implementation IdentityUser: Microsoft Docs | Code at Github (aspnet/Identity) IdentityUser<TKey, TLogin, TRole, TClaim> : Microsoft Docs | Code at Github (aspnet/Identity) IdentityRole implementation IdentityRole:… Read More

Continue Reading

Domain events in C#

An event is something that has happened in the past. A domain event is, something that happened in the domain that you want other parts of the same domain (in-process) to be aware of. The notified parts usually react somehow to the events. Domain events: design and implementation Benefits Since domain events are… well, events, it comes with all the benefits and use cases that you would have if you implement some sort of event driven architecture: Reduce coupling between the effect and the consequence: creating a user and notifying that a user was created have different levels of complexity, different responsibilities, different reasons to change… You won’t have a… Read More

Continue Reading