0
votes

I'm new to breeze. My data looks like this:

{
    id: 1,
    name: 'Robert',
    hobbies: ['Skiing', 'Surfing'],
    address: {
        street: 'Sample Street',
        city: 'Sampleville',
        country: 'Belgium'
    }
}

How do I create this structure in the metadata store programmatically?

1
@kadumel by EF, do you mean .Net Entity Framework? If so, no, I'm not - using mongoose.studds

1 Answers

1
votes

I'm assuming that you are not using Entity Framework.

The Json for the Breeze native metadata format for your model is shown below, with one caveat. The 'hobbies' property ( an array of data properties) is not YET supported in Breeze 1.3.4. However, it will be supported in our next major release that supports NoSQL datastores like Mongo. I didn't run this thru a json parser, so there may be minor syntax errors, but this should give you the right idea.

var jsonMetadata = {
   "metadataVersion":"1.0.4",
   "dataServices":[ {
         "serviceName":"api/Foo/",
         "hasServerMetadata":true,
         "jsonResultsAdapter":"webApi_default",
         "useJsonp":false
      } ],
   "structuralTypes":[ {
         "shortName":"person",
         "namespace":"YourNamespace",
         "dataProperties":[ 
             {  "name":"id",      "dataType":"Int32" },
             {  "name":"name",    "dataType":"String" },
             {  "name: "hobbies", "dataType: "String", isScalar: false },      
             {  "name":"address", "complexTypeName":"address:#YourNamespace" } 
         ] }, {
         "shortName":"address",
         "namespace":"YourNamespace",
         "isComplexType":true,
         "dataProperties":[ 
             {  "name":"street",  "dataType":"String" },
             {  "name":"city",    "dataType":"String" },
             {  "name: "country", "dataType: "String" }    
         } ]
 }  

You would call this via something like

 myEntityManager.metadataStore.importMetadata(jsonMetadata);

I've deliberately left out ( taken the defaults) metadata for validations, whether the properties are nullable or not, the maxLength of your string properties (if any) and several other items. The Breeze documentation contains more info on these.