コード例 #1
0
        private static StorageInfo CreateSimpleStorageModel()
        {
            var storage = new StorageInfo("Storage");

            // Model:
            // class A:Entity {int Id, int Data}
            // class B:A {int Id}
            // class C:B {int Id; A RefA; B RefB; C RefC}

            var tA = new TableInfo(storage, "A");
            var tB = new TableInfo(storage, "B");
            var tC = new TableInfo(storage, "C");

            var idA = new ColumnInfo(tA, "Id", new TypeInfo(typeof(int)));
            var idB = new ColumnInfo(tB, "Id", new TypeInfo(typeof(int)));
            var idC = new ColumnInfo(tC, "Id", new TypeInfo(typeof(int)));

            var refCA = new ColumnInfo(tC, "RefA", new TypeInfo(typeof(int)));
            var refCB = new ColumnInfo(tC, "RefB", new TypeInfo(typeof(int)));
            var refCC = new ColumnInfo(tC, "RefC", new TypeInfo(typeof(int)));

            var dataA = new ColumnInfo(tA, "Data", new TypeInfo(typeof(int)));

            var pkA = new PrimaryIndexInfo(tA, "PK_A");
            var pkB = new PrimaryIndexInfo(tB, "PK_B");
            var pkC = new PrimaryIndexInfo(tC, "PK_C");

            new KeyColumnRef(pkA, idA);
            new KeyColumnRef(pkB, idB);
            new KeyColumnRef(pkC, idC);
            pkC.PopulateValueColumns();
            pkA.PopulateValueColumns();

            var ixRefCA = new SecondaryIndexInfo(tC, "FK_CRefA");

            new KeyColumnRef(ixRefCA, refCA);
            ixRefCA.PopulatePrimaryKeyColumns();
            var ixRefCB = new SecondaryIndexInfo(tC, "FK_CRefB");

            new KeyColumnRef(ixRefCB, refCB);
            ixRefCB.PopulatePrimaryKeyColumns();
            var ixRefCC = new SecondaryIndexInfo(tC, "FK_CRefC");

            new KeyColumnRef(ixRefCC, refCC);
            ixRefCC.PopulatePrimaryKeyColumns();

            var fkCRefA = new ForeignKeyInfo(tC, "FK_CRefA");

            fkCRefA.PrimaryKey = pkA;
            fkCRefA.ForeignKeyColumns.Set(ixRefCA);

            var fkCRefB = new ForeignKeyInfo(tC, "FK_CRefB");

            fkCRefB.PrimaryKey = pkB;
            fkCRefB.ForeignKeyColumns.Set(ixRefCB);

            var fkCRefC = new ForeignKeyInfo(tC, "FK_CRefC");

            fkCRefC.PrimaryKey = pkC;
            fkCRefC.ForeignKeyColumns.Set(ixRefCC);

            var fkCA = new ForeignKeyInfo(tC, "FK_CA");

            fkCA.PrimaryKey = pkA;
            fkCA.ForeignKeyColumns.Set(pkC);

            var fkBA = new ForeignKeyInfo(tB, "FK_BA");

            fkBA.PrimaryKey = pkA;
            fkBA.ForeignKeyColumns.Set(pkB);

            storage.Validate();

            return(storage);
        }
コード例 #2
0
        private static StorageInfo CreateSimpleStorageModel()
        {
            var storage = new StorageInfo("Storage");

            // Types table
            var t   = new TableInfo(storage, "Types");
            var tId = new ColumnInfo(t, "Id")
            {
                Type = new TypeInfo(typeof(int), false)
            };
            var tValue = new ColumnInfo(t, "Value")
            {
                Type = new TypeInfo(typeof(string), 1024)
            };
            var tData = new ColumnInfo(t, "Data")
            {
                Type = new TypeInfo(typeof(byte[]), 1024 * 1024)
            };

            var tiPk = new PrimaryIndexInfo(t, "PK_Types");

            new KeyColumnRef(tiPk, tId);
            tiPk.PopulateValueColumns();

            var tiValue = new SecondaryIndexInfo(t, "IX_Value");

            new KeyColumnRef(tiValue, tValue);
            tiValue.PopulatePrimaryKeyColumns();

            var tiFt = new FullTextIndexInfo(t, "FT_Index");

            new FullTextColumnRef(tiFt, tValue);

            // Objects table
            var o   = new TableInfo(storage, "Objects");
            var oId = new ColumnInfo(o, "Id")
            {
                Type = new TypeInfo(typeof(long), false)
            };
            var oTypeId = new ColumnInfo(o, "TypeId")
            {
                Type = new TypeInfo(typeof(int), false)
            };
            var oValue = new ColumnInfo(o, "Value")
            {
                Type = new TypeInfo(typeof(string), 1024)
            };

            var oiPk = new PrimaryIndexInfo(o, "PK_Objects");

            new KeyColumnRef(oiPk, oId);
            oiPk.PopulateValueColumns();

            var oiTypeId = new SecondaryIndexInfo(o, "IX_TypeId");

            new KeyColumnRef(oiTypeId, oTypeId);
            oiTypeId.PopulatePrimaryKeyColumns();

            var oiValue = new SecondaryIndexInfo(o, "IX_Value");

            new KeyColumnRef(oiValue, oValue);
            new IncludedColumnRef(oiValue, oTypeId);
            oiValue.PopulatePrimaryKeyColumns();

            var ofkTypeId = new ForeignKeyInfo(o, "FK_TypeId")
            {
                PrimaryKey = tiPk,
            };

            ofkTypeId.ForeignKeyColumns.Set(oiTypeId);

            storage.Validate();
            return(storage);
        }