在BreezeJS中手动创建元数据

在BreezeJS中手动创建元数据,breeze,single-page-application,Breeze,Single Page Application,我在尝试手动创建数据模型的元数据时遇到了一些问题。更具体地说,我使用以下命令创建元数据的字符串表示形式,然后将其保存到本地文件中 var metadata = JObject.Parse(new EFContextProvider<HelixDtoContext>().Metadata()); 我希望元数据包括LayoutManagerState复杂属性;然而,它并没有做到这一点 "entityType": [ { "name": "AppState", "ke

我在尝试手动创建数据模型的元数据时遇到了一些问题。更具体地说,我使用以下命令创建元数据的字符串表示形式,然后将其保存到本地文件中

var metadata = JObject.Parse(new EFContextProvider<HelixDtoContext>().Metadata());
我希望元数据包括LayoutManagerState复杂属性;然而,它并没有做到这一点

"entityType": [
  {
    "name": "AppState",
    "key": {
      "propertyRef": {
        "name": "Id"
      }
    },
    "property": [
      {
        "name": "Id",
        "type": "Edm.Int32",
        "nullable": "false",
        "annotation:StoreGeneratedPattern": "Identity"
      },
      {
        "name": "ViewOptionsDialogState",
        "type": "Edm.Self.ViewOptionsDialogState",
        "nullable": "false"
      }
    ]
  },

如您所见,元数据中没有名为
LayoutManagerState
的属性。

我无法重现您的失败。

我使用了一个现有的应用程序(Todo示例之一),并将您的两个类放入其中,如下所示:

public class LayoutManagerState {
    public string Widgets { get; set; }
}

public class AppState {
    public int Id{ get; set; }
    public LayoutManagerState LayoutManagerState { get; set; }
}
我将新的
DbSet
添加到
DbContext
中,如下所示:

public DbSet<AppState> AppStates { get; set; }
Breeze进口的产品也很好,这一测试证明了这一点:

manager.metadataStore.getEntityType('LayoutManagerState'); // returns the complex type

您认为差异的原因是什么?

我找到了问题所在;我的解决方案中有以下项目。1) MyApp.Models 2)MyApp.Dtos 3)MyApp.UI 4)MyApp.MetadataGenerator。当MVC应用程序启动(MyAPP.UI)时,我调用MyAPP.meatataggenerator中返回元数据字符串的方法。当我这样做的时候,我没有得到我的数据模型的完整表示。但是,如果我将MetadataGenerator作为独立控制台应用程序运行,那么LayoutManagerState将包含在元数据中。
"complexType": {
  "name": "LayoutManagerState",
  "property": {
    "name": "Widgets",
    "type": "Edm.String",
    "maxLength": "4000",
    "fixedLength": "false",
    "unicode": "true"
  }
},
"entityType": [
  {
    "name": "AppState",
    "key": {
      "propertyRef": {
        "name": "Id"
      }
    },
    "property": [
      {
        "name": "Id",
        "type": "Edm.Int32",
        "nullable": "false",
        "annotation:StoreGeneratedPattern": "Identity"
      },
      {
        "name": "LayoutManagerState",
        "type": "Edm.Self.LayoutManagerState",
        "nullable": "false"
      }
    ]
  },
  {
    "name": "TodoItem",
    "key": {
      "propertyRef": {
        "name": "Id"
      }
    },
    "property": [
      {
        "name": "Id",
        "type": "Edm.Int32",
        "nullable": "false",
        "annotation:StoreGeneratedPattern": "Identity"
      },
      {
        "name": "Description",
        "type": "Edm.String",
        "maxLength": "30",
        "fixedLength": "false",
        "unicode": "true",
        "nullable": "false"
      },
      {
        "name": "IsDone",
        "type": "Edm.Boolean",
        "nullable": "false"
      }
    ]
  }
],
manager.metadataStore.getEntityType('LayoutManagerState'); // returns the complex type