Direct access to NMemory.Database

Jan 13, 2015 at 4:07 PM
Edited Jan 13, 2015 at 4:09 PM

In our project we need to temporarily disable/reenable some FKs to load a little portion of self-referencing records into the database. NMemory doesn't seem to provide any DDL syntax which one could run over the native db-connection, but it exposes the normal C# API for such operations.

The philosophy of Effort (as I understand it) is to abstract away NMemory which does make sense of course, but I wonder how would you recommend us to implement our requirement the best way?

For now we have to use rather ugly and dangerous private reflection to reach the NMemory database
PropertyInfo dbcProp = dbContext.Database.Connection.GetType().GetProperty("DbContainer", BindingFlags.NonPublic | BindingFlags.Instance);
object dbContainer = dbcProp.GetValue(dbContext.Database.Connection);

PropertyInfo ndbProp = dbContainer.GetType().GetProperty("Internal");
var ndb = (NMemory.Database)ndbProp.GetValue(dbContainer);
Thank you,
Jan 25, 2015 at 4:00 PM

I provided an interface for accessing database functions that are not available through Entity Framework.

The implementation disables relations. I will just need to make that particular method public.

Thank you for the suggestion!
Jan 27, 2015 at 7:50 AM
Thanks for the reply!

Unfortunately IDbManager doesn't open up enough access to the underlying NMemory database. Ideally I would just need a reference to NMemory.Database to locate and disable one specific relation rather than all of them.

And let me just slightly correct the statement
The implementation disables relations.
DbContainerManagerWrapper.SetRelations WILL disable relations once is fixed. Right now it just loops over an empty collection db.Tables.GetAllRelations().