示例#1
0
        public void Node_Create_Person()
        {
            NodeSchema n = new NodeSchema(name: "person");

            n.Attributes.Add(new Attribute(name: "FirstName", type: new AttributeText()));
            n.Attributes.Add(new Attribute(name: "LastName", type: new AttributeText()));
            n.Attributes.Add(new Attribute(name: "DateOfBirth", new AttributeDatum()));
            n.Edges.Add(new EdgeSchema(name: "likes"));
            n.Edges.Add(new EdgeSchema(name: "married"));
            n.Edges.Add(new EdgeSchema(name: "friend"));

            n.Edges[0].Constraints.Add(new Constraint(name: "person"));
            n.Edges[1].Constraints.Add(new Constraint(name: "person"));
            n.Edges[2].Constraints.Add(new Constraint(name: "person"));

            n.Edges[0].Attributes.Add(new Attribute(name: "rating", type: new AttributeEuro()));

            SchemaController controller = new SchemaController(new MsSqlGraphSchemaService());
            var yaml = controller.Serialize(n);
            var r    = controller.Deserialize(yaml);
            var sql  = controller.Service.CreateScript(r);

            Assert.True(sql == @"CREATE TABLE node.person (
ID INTEGER PRIMARY KEY,
FirstName  NTEXT,LastName  NTEXT,DateOfBirth DATETIME,
) AS NODE;
CREATE TABLE edge.likes (
rating DECIMAL,CONSTRAINT EC_LIKES CONNECTION (
node.person TO node.person
)
) AS EDGE;

CREATE TABLE edge.married (
CONSTRAINT EC_MARRIED CONNECTION (
node.person TO node.person
)
) AS EDGE;

CREATE TABLE edge.friend (
CONSTRAINT EC_FRIEND CONNECTION (
node.person TO node.person
)
) AS EDGE;

");
        }