This project has moved and is read-only. For the latest updates, please go here.

TableCollection.relations and TableCollection.relationMapping out of sync

Jan 13, 2015 at 6:22 PM
Edited Jan 27, 2015 at 8:53 AM

In our project we use Effort framework with NMemory database under the hood. The database is created automatically from the Code First classes. Due to some circular references in the data model (for historical reasons) we have troubles inserting cross-referencing records (A references B whilst B references A, and the link is non-optional).

NMemory appears to provide an API for disabling foreign key constraints.

Strangely TableCollection.GetAllRelations() method always returns an empty list, and I see in the debugger that both collections relations and relationsPublic are always empty. I don't exclude that Effort is somehow misusing NMemory, but this is just an observation which right now isn't a real problem.

The relations I need are actually stored only in relationMapping collection, to which unfortunately I have no public access. Internal methods GetReferringRelations and GetReferredRelations do exist and aren't used from within the NMemory assembly, which makes me believe then were originally planned as public methods.

I would be happy if
  1. Either TableCollection.relations and TableCollection.relationMapping collections were synchronized by some internal mechanism
  2. Or the library gave some public access to TableCollection.relationMapping, e.g. by declaring methods GetReferringRelations and GetReferredRelations as public.
Anyway it looks like TableCollection.relations field was added (in rev a610ca2) in a rather unclean way...

Could you please have a look?

Jan 25, 2015 at 5:01 PM

Thank you for reporting this issue! It will give it a look, it is entirely possible that something is screwed up.
Jan 27, 2015 at 9:05 AM
That would be great! And I suspect the change can be quite trivial, like
  1. Remove both collections relations and relationsPublic
  2. Let GetAllRelations return IEnumerable<IRelation> instead of IList **
  3. With a simple implementation relationMapping.Values.SelectMany(gr => gr.Referred)
** Same idea for tablesPublic and GetAllTables
Mar 20, 2015 at 2:51 PM
Thank you azabluda for posting all of this - with a couple of small tweaks and a recompilation I've eventually got Effort to work!

The required fix is even simpler than you suggest: TableCollection.CreateRelation just needs to remember to add its new creation to the relations list before it returns.