Dynamically created context add set into instance

by JayData

HTML

<script src="http://jaydata-cdn.s3.amazonaws.com/datajs-1.0.3-patched.js"></script>
<script src="http://include.jaydata.org/jaydata.js"></script>

JavaScript

var odataServiceUrl = 'http://jaydata.org/examples/Northwind.svc';

//create an empty context type
$data.EntityContext.extend('NorthwindModel.Context', {

});

var myContext = new NorthwindModel.Context({ name: 'oData', oDataServiceHost: odataServiceUrl });
myContext.onReady(function(ctx){
    var contextInstance = ctx,
        contextType = contextInstance.getType(),
        providerType = contextInstance.storageProvider.getType(); 
    
    //define an entity
    $data.Entity.extend('NorthwindModel.Product', {
         'Product_ID': { 'key':true, 'type':'Edm.Int32', 'nullable':false, 'computed':true },
         'Supplier_ID': { 'type':'Edm.Int32', 'nullable':true },
         'Category_ID': { 'type':'Edm.Int32', 'nullable':true },
         'Product_Name': { 'type':'Edm.String', 'nullable':false, 'required':true, 'maxLength':40 },
         'English_Name': { 'type':'Edm.String', 'nullable':true, 'maxLength':40 },
         'Quantity_Per_Unit': { 'type':'Edm.String', 'nullable':true, 'maxLength':20 },
         'Unit_Price': { 'type':'Edm.Decimal', 'nullable':true },
         'Units_In_Stock': { 'type':'Edm.Int16', 'nullable':true },
         'Units_On_Order': { 'type':'Edm.Int16', 'nullable':true },
         'Reorder_Level': { 'type':'Edm.Int16', 'nullable':true },
         'Discontinued': { 'type':'Edm.Boolean', 'nullable':false, 'required':true },
         'Category': { 'type':'NorthwindModel.Category', 'inverseProperty':'Products' }     
      });
    //add member (EntitySet definition) dynamically to empty context
    contextType.addMember('Products', { type: $data.EntitySet, elementType: NorthwindModel.Product });
    
    //an other entity
    $data.Entity.extend('NorthwindModel.Category', {
         'Category_ID': { 'key':true, 'type':'Edm.Int32', 'nullable':false, 'computed':true },
         'Category_Name': { 'type':'Edm.String', 'nullable':false, 'required':true, 'maxLength':15 },
         'Description': { 'type':'Edm.String', 'nullable':true,...