How to add context metadata to my objects without using EF? [SOLVED]

I need to implement an architecture where, unfortunately, we use SharePoint 2013, as, in fact, our main database. (Not my choice if you hadn't chosen this). I have an App.Net MVC facade application on the server, processing data from SP and several other data sources, and then JavaScript SPA as a client. An additional wrinkle is that the client must work offline, so I need to use IndexedDB to store data for offline access.

This seems like the perfect use case for breeze.js. My main architecture is to define a strongly typed model in the MVC facade that will wrap the untyped data that I get from SP (in the form [[property ”] object using the client client object model). Breeze will handle the synchronization between this model and the client, and I will use the export / import functions to cache data in IndexedDB as needed.

So far so good. But ... examples of SOA on the Breeze website are still under development (and for me this is fundamentally an SOA architecture, with each SP list containing a composition that needs to be compiled). The closest I can find is a NoDB sample, but this is the metadata of the hardcodes on the client. I would like to establish relationships and validations in the MVC model, and then pass them to the client, so the validation can work with the same declaration in both places.

Is it possible? If so - how? If someone has no workaround or better idea? I have already come to terms with the definition of the model in two separate places (the facade and, implicitly, the structure of the SP lists). I would very much like to avoid its implementation for the third time in the client. I am open to let breeze.js talk directly with SP REST endpoints, but my understanding from https://stackoverflow.com/a/960671/ ... is that the implementation is erroneous and does not provide the required metadata.

Permission . Based on the answer below, I came to the following solution:

1) Create a service link from the SP ListData.svc endpoint, thus creating the edmx and proxy classes.

2) Extend ContextProvider in my repository and override BuildJsonMetadata as follows:

 protected override string BuildJsonMetadata() { XDocument xDoc = XDocument.Load(HttpContext.Current.Server.MapPath("PATH_TO_EDMX")); String xString = xDoc.ToString(); xString = xString.Replace("DATA_SERVICE_NAMESPACE", "APP_NAMESPACE"); xDoc = XDocument.Parse(xString); var jsonText = CsdlToJson(xDoc); return jsonText; } 

3) Change breeze.js very slightly, edit line 12383:

 var schema = metadata.schema || metadata["edmx:Edmx"]["edmx:DataServices"].schema; 

(Perhaps I suggested that this is fixed in ContextProvider by selecting the descendant rather than the root node for my xDoc)

4) - Optionally use the @Christoff very useful T4TS.tt template script to generate d.ts from proxy classes so I can have a security type on data that is loaded by breezes.

So far, so good with this setting - I can do basic CRUD with metadata supported by SP as a data source.

+2
source share
1 answer

As in v 1.2.7 , we documented the Breeze metadata schema, and the json objects that adhere to this schema that are returned from your web service will now be executed by Breeze.

--- previous message below

We are in the process of documenting how to expose arbitrary server-side metadata for the next week or so, and then shortly thereafter, examples will be given of how to use an arbitrary web service. There are also some small code changes.

Until these documents are completed, the best solution would be to create your metadata on the client and use the jsonResultsAdapter to formulate the results of your service call in the entity. The metadata that you create on the client will be exactly the same as the metadata that you ultimately create on the server and send it to the client.

Hope this helps.

+3
source

All Articles