I am looking in to using breezejs and have a few questions in terms of its capabilities and the best practices that come with it.
Thanks
Pawel's post is correct that you should start by calling
breeze.config.initializeAdapterInstances
To actually create the client side metadata you would write something like this. ( A simple example).
initializeMetadataStore(myEntityManager.metadataStore);
function initializeMetadataStore(metadataStore) {
var et = new EntityType({
shortName: "Person",
namespace: "Sample_WebApi.Models"
});
et.addProperty( new DataProperty({
name: "personId",
dataType: DataType.Int32,
isNullable: false,
isPartOfKey: true,
}));
et.addProperty(new DataProperty({
name: "firstName",
dataType: DataType.String,
isNullable: false,
}));
et.addProperty(new DataProperty({
name: "lastName",
dataType: DataType.String,
isNullable: false,
}));
et.addProperty(new DataProperty({
name: "birthDate",
dataType: DataType.DateTime,
isNullable: true
}));
et.addProperty(new NavigationProperty({
name: "meals",
entityTypeName: "Meal",
isScalar: false,
associationName: "personMeals"
}));
metadataStore.addEntityType(et);
et = new EntityType({
shortName: "Meal",
namespace: "Sample_WebApi.Models"
});
et.addProperty(new DataProperty({
name: "mealId",
dataType: DataType.Int32,
isNullable: false,
isPartOfKey: true,
}));
et.addProperty(new DataProperty({
name: "personId",
dataType: DataType.Int32,
isNullable: false,
}));
et.addProperty(new DataProperty({
name: "dateConsumed",
dataType: DataType.DateTime,
isNullable: false,
}));
et.addProperty(new NavigationProperty({
name: "person",
entityTypeName: "Person",
isScalar: true,
associationName: "personMeals",
foreignKeyNames: ["personId"]
}));
et.addProperty(new NavigationProperty({
name: "dishes",
entityTypeName: "Dish",
isScalar: false,
associationName: "mealDishes",
}));
metadataStore.addEntityType(et);
et = new EntityType({
shortName: "Dish",
namespace: "Sample_WebApi.Models"
});
et.addProperty(new DataProperty({
name: "dishId",
dataType: DataType.Int32,
isNullable: false,
isPartOfKey: true,
}));
et.addProperty(new DataProperty({
name: "foodName",
dataType: DataType.String,
isNullable: false,
}));
et.addProperty(new DataProperty({
name: "servingSize",
dataType: DataType.Double,
isNullable: false,
}));
et.addProperty(new NavigationProperty({
name: "food",
entityTypeName: "Food",
isScalar: true,
associationName: "DishFood",
foreignKeyNames: ["foodName"]
}));
metadataStore.addEntityType(et);
et = new EntityType({
shortName: "Food",
namespace: "Sample_WebApi.Models"
});
et.addProperty(new DataProperty({
name: "foodName",
dataType: DataType.String,
isNullable: false,
isPartOfKey: true,
}));
et.addProperty(new DataProperty({
name: "calories",
dataType: DataType.Int32,
isNullable: false,
}));
metadataStore.addEntityType(et);
}
1 You can configure metadata on the client. To turn off server metadata try this:
config.initializeAdapterInstances(
new DataService({
serviceName: "yourServiceNameHere",
hasServerMetadata: false }));
2 Please look at the Breeze docs and api. Start here EntityType and here Extending Entities
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With