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

NMemory enables to define relations between tables that will prevent foreign key violation. This requires to have indexes built on the foreign key field and on the unique key field. You have to specify these indexes and the data conversions between the indexed fields. The following example demonstrates a creation of a one to many relation between people and groups.

public class MyDatabase : Database
    public MyDatabase()
        var peopleTable = base.Tables.Create<Person, int>(p => p.Id);
        var groupTable = base.Tables.Create<Group, int>(g => g.Id);

        var peopleGroupIdIndex = peopleTable.CreateIndex(
            new RedBlackTreeIndexFactory<Person>(), 
            p => p.GroupId);

            x => x, 
            x => x);

        this.People = peopleTable;
        this.Groups = groupTable;

    public ITable<Person> People { get; private set; }

    public ITable<Group> Groups { get; private set; }

Last edited Nov 10 at 6:25 AM by zzzprojects, version 7


No comments yet.