微风服务器端元数据是强制性的还是可以在客户端定义? [英] Is breeze server side metadata mandatory or can it be be defined client-side?

查看:68
本文介绍了微风服务器端元数据是强制性的还是可以在客户端定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑使用breezejs,并对其功能和最佳实践有一些疑问。

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.


  1. 服务器端metada是否必须存在?如果我有一个非EF WebApi控制器,是否仍需要用ProviderContext封装它并实现元数据?如果是这样,元数据的格式是什么?

  2. 如果我能够在服务器端省略元数据并仅实现可查询的动作过滤器,我仍可以编写客户端代码来定义元数据?我在哪里可以找到有关此操作的信息?

  3. 我有一个名为Job的服务器模型类,其ID和名称为简单属性,而对象属性为Company,它指向一个服务器端模型类称为Company,它具有ID和名称。作业可以是机密的(通过Job上的布尔IsConfidential属性),在这种情况下,即使它们仍然具有companyId,也不应将该属性发送给客户端。相反,应该有一个发送到客户端的服务器端计算属性,称为CompanyName(对于非机密作业,基本上是Company.Name;对于机密作业,则是 Confidential)。管理员角色用户应该可以查看和编辑CompanyId,但普通用户则不能看到或发布/放置该值。您如何轻松完成此任务?微风在发送和接收非模型ViewModel(较少的属性和一些计算的属性)方面处理得很好吗?

  4. ODataActionFilter的源代码源是我可以使用和更改的东西吗?我想要的目的是什么?

  5. 为EF之外的其他东西(例如Telerik OpenAccess)创建WebApi控制器有多困难?

  1. Does server side metada have to exist? If I have a non EF WebApi controller do I still have to wrap it with the ProviderContext and implement metadata? If so, what is the format of the metadata?
  2. If I am able to omit metadata on the server side and just implement the queryable actionfilter, can I still write client side code to define the metadata? Where would I find information on how to do this?
  3. I have a server Model class called Job with an id and name, which are simple properties and an object property called Company which points to a server side model class called Company which has an id and name. Job(s) can be confidential (through a boolean IsConfidential property on Job) in which case even though they still have a companyId, that property should not be sent to the client. Instead there should be a server-side computed property called CompanyName (basically Company.Name for non-confidential Jobs and "Confidential" for confidential jobs) that is sent to the client. Admin roled users should be able to see and edit CompanyId but regular users should not be able see or post/put that value. How do you accomplish this in breeze? Does breeze deal well with sending and receiving non-Model ViewModels (less properties and some computed properties)?
  4. Is the source for the source code for the ODataActionFilter something I can use and change for any purpose I want?
  5. How difficult would it be to create WebApi Controllers for something other than EF - maybe like Telerik OpenAccess?

谢谢

推荐答案

Pawel的帖子是正确的,您应该先致电

Pawel's post is correct that you should start by calling

breeze.config.initializeAdapterInstances

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);
}

这篇关于微风服务器端元数据是强制性的还是可以在客户端定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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