Is breeze server-side metadata mandatory or can it be defined on the client side?

I use breezejs and have a few questions in terms of its capabilities and best practices that come with it.

  • Should the server side of metada exist? If I don't have an EF WebApi controller, will I still have to wrap it with a ProviderContext and implement metadata? If so, what is the metadata format?
  • If I can omit server-side metadata and just implement the requested actionfilter, can I write client-side code to define metadata? Where can I find information on how to do this?
  • I have a server model class called Job with an identifier and a name, which are simple properties and a property of a Company object that points to a server-side model class called Company, which has an identifier and name. Job (s) can be confidential (via the IsConfidential boolean property on Job), in which case, even if they still have companyId, this property should not be sent to the client. Instead, there should be a server-side computational property called CompanyName (mainly Company.Name for non-confidential jobs and "Confidential" for confidential jobs) that is sent to the client. Users started by the administrator should be able to see and edit CompanyId, but regular users should not see or publish / put this value. How do you do it in the wind? Is it easy to cope with sending and receiving modeled ViewModels (fewer properties and some computed properties)?
  • Is there a source code for ODataActionFilter that I can use and modify for any purpose I want?
  • How difficult would it be to create WebApi controllers for something other than EF, perhaps like Telerik OpenAccess?

thanks

+6
source share
3 answers

The correct sending message is correct, you should start by calling

breeze.config.initializeAdapterInstances

To create client-side metadata, you should 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); } 
+6
source

1 You can customize metadata on the client. To disable server metadata, try the following:

 config.initializeAdapterInstances( new DataService({ serviceName: "yourServiceNameHere", hasServerMetadata: false })); 

2 Please see the Breeze and api docs. Start here EntityType and here Entity Extension

+2
source

To question 3: There are several possible approaches to this.

First, you can return objects that are not β€œentities” for the client, and they can take almost any form. This way you can determine which properties to include or exclude from them. Basically, any object returned from the server for which it is impossible to find matching metadata on the client side will be returned as an anon json object. Please note that these anonymous objects will not be wrapped by any binding library, i.e. ko, backbone, angular, etc., And these objects will not be added to the entityManager cache.

The second option is to use json.net serialization intercept points. (see json.net help ). This will allow you to conditionally suppress serialization of selected properties. Be careful with this, because if you try to save any objects that were returned to the client after "disinfection", you will need to restore these properties to their original values ​​(on the server) before saving is completed.

To question 4: the breeze is open source and available on github. You are free to use the source.

In question 5: In the latest versions of breeze.webApi.dll, we have already reorganized our special EF code from our core webApi function for this very purpose. We have not finished the documentation yet, but you can take a look at the "ContextProvider" and "EFContextProvider" classes in the Breeze.webApi project to find out what another provider might be looking at. In the near future, we plan to show the NoSQL provider for something like mongodb. Please vote in favor of a bridge user for any specific suggestions in this area.

+2
source

All Articles