我怎样才能上下文元数据添加到我的实体,而无需使用EF? [解决] [英] How can I add context metadata to my entities without using EF? [Resolved]

查看:236
本文介绍了我怎样才能上下文元数据添加到我的实体,而无需使用EF? [解决]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要实现的地方,不幸的是,我们正在使用SharePoint 2013年,有效的架构,我们的原则数据库。 (不是我的选择,如果你还没有回升,最多)。我在服务器上一个Asp.Net MVC应用程序的外观,处理来自SP的数据组成一对夫妇的其他数据源,然后一个JavaScript SPA作为客户端。一个额外的皱纹是客户需要能够脱机工作,所以我需要使用索引资料来存储数据进行离线访问。

I have to implement an architecture where, unfortunately, we are using SharePoint 2013 as, effectively, our principle database. (Not my choice, in case you hadn't picked that up). I have an Asp.Net MVC facade application on the server, handling composition of data from SP and a couple of other data sources, and then a JavaScript SPA as client. An additional wrinkle is that the client needs to be able to work offline, so I need to use IndexedDB to store the data for offline access.

这似乎是一个完美的用例为breeze.js。我的基本架构是定义在MVC门面强类型的模式,将包裹类型化的数据,我从SP得到(形式为对象的[属性] - 使用SP客户端对象模型)。微风将处理这种模式和客户端之间的同步,并根据需要,我将使用导出/导入功能来缓存数据在IndexedDB的。

This seems a perfect use-case for breeze.js. My basic architecture is to define a strongly typed model in the MVC facade that will wrap the untyped data I get from SP (in the form object["property"] - using the SP Client Side Object Model). Breeze will handle synchronization between this model and the client, and I will use the export/import functionality to cache data in IndexedDB as required.

到目前为止好。但是......在微风的网站上的SOA实例仍处于开发阶段(对我来说,这根本就是一个SOA架构,每个SP一个列出来组成服务)。我能找到最接近的是 NoDB 样本,但是,从这个硬codeS元客户。我想建立MVC模式的关系和验证,然后通过向客户传递这些,所以验证可以流掉两地相同的声明。

So far so good. But... the SOA examples on the breeze site are still under development (and to me, this is fundamentally an SOA architecture, with each SP List a service to be composed). The closest thing I can find is the NoDB sample but this hard-codes metadata on the client. I'd like to establish relationships and validation in the MVC model, and then pass these through to the client, so validation can run off the same declaration in both places.

这可能吗?如果是的话 - 如何?如果不是有没有人有一种变通方法或更好的主意?我已经辞职,以界定在两个不同的地方的模型(门面,并明确了SP名单的结构)。这时候我真希望避免实施它在客户端第三次。我打开有breeze.js直接交谈的SP REST端点,但是从我的理解 http://stackoverflow.com/a /1014822分之15364503是实现是有缺陷的,不公开所需的元数据。

Is this possible? If so - how? If not does anyone have a workaround or a better idea? I'm already resigned to defining the model in two separate places (the facade and, implicitly, the structure of the SP lists). I would dearly like to avoid implementing it a third time in the client. I'm open to having breeze.js talk directly to the SP REST endpoints, but my understanding from http://stackoverflow.com/a/15364503/1014822 is that the implementation is flawed and does not expose the required metadata.

分辨率:基于下面的接受的答案,我来到了以下解决方案:

Resolution: Based on the accepted answer below, I came to the following solution:

1)生成从SP ListData.svc端点的服务引用 - 从而创造一个EDMX和代理类

1) Generate a service reference from the SP ListData.svc endpoint - thus creating an edmx and proxy classes.

2)扩展ContextProvider在我的仓库,并覆盖 BuildJsonMetadata 像这样:

2) Extend ContextProvider in my Repository and override BuildJsonMetadata like so:

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)修改breeze.js非常轻微,编辑行12383:

3) Modify breeze.js very slightly, editing line 12383:

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

(我可以美元的选择后代,而不是我的XDOC根节点p $ psumably也已在ContextProvider固定这)

(I could presumably also have fixed this in the ContextProvider by choosing a descendant rather than the root node for my xDoc)

4) - 可以选择使用@克里斯托夫的非常有用的 T4TS.tt 模板脚本生成d.ts从服务代理类,所以我可以对数据类型安全的微风负载。

4) - Optionally use @Christoff's very useful T4TS.tt template script to generate a d.ts from the service proxy classes so I can have type safety on the data that breeze loads.

到目前为止,一切与此设置好的 - 我可以执行与元数据的基本的CRUD,通过SP的支持作为数据源

So far so good with this setup - I can perform basic CRUD with metadata, backed by SP as a data source.

推荐答案

由于 v 1.2.7 ,我们已经证明,坚持这样的模式,它是从返回微风的元数据架构和JSON对象您的Web服务现在将由微风兑现。

As of v 1.2.7, We have documented Breeze's metadata schema, and json objects that adhere to this schema that are returned from your webservice will now be honored by Breeze.

--- previous后低于

--- previous post below

我们在记录如何在未来一周左右暴露任意服务器端的元数据的过程中,遵循此后不久通过的如何消费任意Web服务的一些例子。有参与其中的几个小code的变化。

We are in the process of documenting how to expose arbitrary server side metadata over the next week or so, followed soon thereafter by some examples of how to consume an arbitrary web service. There are a few small code changes involved as well.

有关目前,直至这些文档是否齐全,最好的解决方法是在客户端上创建元数据,并使用jsonResultsAdapter为您服务调用的结果塑造成实体。在客户端上创建元数据将是完全一样,你最终将在服务器上创建和发送到客户端的元数据。

For the time being, until these docs are complete, the best workaround is to create your metadata on the client and use a jsonResultsAdapter to shape the results of your service call into "entities". The metadata you create on the client will be exactly the same as the metadata that you will eventually be creating on the server and sending down to the client.

希望这有助于。

这篇关于我怎样才能上下文元数据添加到我的实体,而无需使用EF? [解决]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆