当我尝试手动创建数据模型的元数据时,我遇到了一些问题。更具体地说,我使用以下命令创建元数据的字符串表示形式,然后将其保存到本地文件。
var metadata = JObject.Parse(new EFContextProvider<HelixDtoContext>().Metadata());
但是,当我这样做的时候,有一些缺失的信息。以下Dto
public class LayoutManagerState
{
public string Widgets { get; set; }
}
public class AppState
{
public int Id{ get; set; }
public ViewOptionsDialogState ViewOptionsDialogState { get; set; }
public LayoutManagerState LayoutManagerState { get; set; }
...
}
我希望元数据包含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
的属性。
答案 0 :(得分:0)
我无法重现您的失败。
我拿了一个现有的应用程序(其中一个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; }
然后我查看通过线路发送的元数据...它看起来很好。以下是三个实体类型定义,顶部是复杂类型:
"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"
}
]
}
],
Breeze也很好地导入了它,正如这个测试所证明的那样:
manager.metadataStore.getEntityType('LayoutManagerState'); // returns the complex type
您认为差异的原因是什么?