-
Notifications
You must be signed in to change notification settings - Fork 2
Storage Engine: Entity Framework 6
Most of the work is already done for you, but there are a few things you'll have to do yourself in order to use RdbmsEventStore with Entity Framework 6.
There is a default implementation as Event<TId, TStreamId>
in the library, but since EF6 doesn't support generic entity types, you must create a non-generic subclass for it:
public class YourEventType : Event<Guid, string> { } // or Event<long, long>, etc
The id types can be the same or not, it's entirely up to you. If you want to add metadata, such as the user id of the user who triggered the event, this is where you do that.
This can also inherit directly from the built-in EventStoreContext<TEvent>
:
public class YourEventStoreContext : EventStoreContext<YourEventType>
{
public YourEventStoreContext() : base("name=NameOfYourConnectionString") { }
}
The constructor parameter is just passed along to the underlying DbContext
. You can of course add other constructors if you need it for e.g. your design-time tooling; this variant at least works with EF Migrations.
var context = new YourEventStoreContext();
var eventFactory = new EventFactory<Guid, string, YourEventType>();
The Entity Framework backing library includes a complete Event Store implementation, so you just need to inject its dependencies and you'll be good to go:
var eventStore = new EntityFrameworkEventStore<Guid, string, YourEventStoreContext, YourEventType>(
context,
eventFactory,
writeLock);
You now have all the pieces in place to start using the Event Store. Go back to Getting Started and keep reading!