locked
Does AutoNumber() not work with a hierarchial schema? RRS feed

  • Question

  • I have this input/schema (using hierarchical entities and schema, because the input is coming from a DSL/grammar):

    module Csla {

        Classes {
            {
                Name = "Test",
                Stereotype = "Object",
                Namespace = "Test",
                Identity = "Id",
                Properties
                {
                    { Name = "foo",
                      Scope = "Public",
                      ReadOnly = true,
                      Type = "bar"
                    }
                }
            }
        }
       
        type BusinessClass
        {
            Name : Text#30;
            Stereotype : Text#10;
            Namespace : Text#50;
            Identity : Text#30;
            Properties : Property*;
        } where identity Name;

        Classes : BusinessClass* where item.Properties <= Properties;
       
        type Property
        {
            Name : Text#30;
            Scope : Text#10;
            ReadOnly : Logical;
            Type : Text#30;
        } where identity Name;

        Properties : Property*;
    }

    Which "works", except that Property really needs to be identified by some unique value (not the Name field).

    If I add an Id field:

             Id : Integer32 = AutoNumber();

    Then my entity becomes invalid - apparently the lack of an explicit Id value in the entity means the types don't match.

    But I can't supply an Id value in the entity, because it is an AutoNumber() in the schema.

    If I make it just an Integer32 in the schema, then I can supply an Id in the entity. BUT I DON'T WANT TO, because I don't want my DSL developer to have to generate unique numeric values!!!

    Really what I want is for Property to have a primary key of (Class.Name + Property.Name) - but I can't figure out how to create a compound key in MSchema, and even if I did know how to do that - how would the Property definition be able to access the Class field values?

    Is MSchema really this limited? The problems I'm fighting with are very, very basic relational database design issues after all...

    Wednesday, April 22, 2009 11:15 PM

Answers

  • This code below works for me.  I think the other issue was blocking.

    We take your point and are working hard to make this a better experience. 

    module Csla {

        Classes {
            {
                Name = "Test",
                Stereotype = "Object",
                Namespace = "Test",
                Identity = "Id",
                Properties =
                {
                    { Name = "foo",
                      Scope = "Public",
                      ReadOnly = true,
                      Type = "bar"
                    }
                }
            }
        }
       
        type BusinessClass
        {
            Name : Text#30;
            Stereotype : Text#10;
            Namespace : Text#50;
            Identity : Text#30;
            Properties : Property*;
        } where identity Name;

        Classes : BusinessClass* where item.Properties <= Properties;
       
        type Property
        {
            Id : Integer32 = AutoNumber();
            Name : Text#30;
            Scope : Text#10;
            ReadOnly : Logical;
            Type : Text#30;
        } where identity Id;

        Properties : Property*;
    }

    Thursday, April 23, 2009 2:09 AM

All replies

  • This code below works for me.  I think the other issue was blocking.

    We take your point and are working hard to make this a better experience. 

    module Csla {

        Classes {
            {
                Name = "Test",
                Stereotype = "Object",
                Namespace = "Test",
                Identity = "Id",
                Properties =
                {
                    { Name = "foo",
                      Scope = "Public",
                      ReadOnly = true,
                      Type = "bar"
                    }
                }
            }
        }
       
        type BusinessClass
        {
            Name : Text#30;
            Stereotype : Text#10;
            Namespace : Text#50;
            Identity : Text#30;
            Properties : Property*;
        } where identity Name;

        Classes : BusinessClass* where item.Properties <= Properties;
       
        type Property
        {
            Id : Integer32 = AutoNumber();
            Name : Text#30;
            Scope : Text#10;
            ReadOnly : Logical;
            Type : Text#30;
        } where identity Id;

        Properties : Property*;
    }

    Thursday, April 23, 2009 2:09 AM
  • Yes, I think your answer in this thread
    http://social.msdn.microsoft.com/Forums/en-US/oslo/thread/89ee0bf6-02f6-4e89-b9e7-fffd8e33115f

    fixes the AutoNumber() issue as well - thanks!
    Thursday, April 23, 2009 2:10 AM