使用breezejs导入元数据脚本会在JSON.parse上引发SyntaxError。我的架构有任何明显的错误?

时间:2013-06-16 12:42:33

标签: breeze

我这样调用代码:

var studyDataService = new breeze.DataService({ serviceName:  _config.RemoteStudyDataServiceName, hasServerMetadata: false });
var mgr = new breeze.EntityManager({ dataService: studyDataService });
mgr.metadataStore.importMetadata(mmg.StudyMetadata);

架构来自服务器端/元数据端点。这不起作用,但我然后使用metadataStore.exportMetadata(),保存该字符串,并将其放在我的脚本中。它看起来像这样:

mmg.StudyMetadata = {
    "schema":
    {
        "namespace": "CodeFirstNamespace",
        "alias": "Self",
        "d4p1:UseStrongSpatialTypes": "false",
        "xmlns:d4p1": "http://schemas.microsoft.com/ado/2009/02/edm/annotation",
        "xmlns": "http://schemas.microsoft.com/ado/2009/11/edm",
        "cSpaceOSpaceMapping": {
            "CodeFirstNamespace.Study": "MMG.Legacy.StudySiteComm.Core.Entities.Study",
            "CodeFirstNamespace.StudySite": "MMG.Legacy.StudySiteComm.Core.Entities.StudySite",
            "CodeFirstNamespace.SiteContact": "MMG.Legacy.StudySiteComm.Core.Entities.SiteContact"
        },
        "entityType": [{ "name": "Study", "key": { "propertyRef": { "name": "StudyID" } }, "property": [{ "name": "StudyID", "type": "Edm.Int32", "nullable": "false", "d4p1:StoreGeneratedPattern": "Identity" }, { "name": "StudyName", "type": "Edm.String", "fixedLength": "false", "maxLength": "100", "unicode": "true", "nullable": "false" }, { "name": "ClientName", "type": "Edm.String", "fixedLength": "false", "maxLength": "100", "unicode": "true", "nullable": "false" }], "navigationProperty": { "name": "StudySites", "relationship": "Self.StudySite_Study", "fromRole": "StudySite_Study_Target", "toRole": "StudySite_Study_Source" } },
            { "name": "StudySite", "key": { "propertyRef": { "name": "SiteID" } }, "property": [{ "name": "StudyID", "type": "Edm.Int32", "nullable": "true" }, { "name": "SiteID", "type": "Edm.Int32", "nullable": "false", "d4p1:StoreGeneratedPattern": "Identity" }, { "name": "ClientID", "type": "Edm.String", "fixedLength": "false", "maxLength": "12", "unicode": "true", "nullable": "false" }], "navigationProperty": [{ "name": "Contacts", "relationship": "Self.SiteContact_StudySite", "fromRole": "SiteContact_StudySite_Target", "toRole": "SiteContact_StudySite_Source" }, { "name": "Study", "relationship": "Self.StudySite_Study", "fromRole": "StudySite_Study_Source", "toRole": "StudySite_Study_Target" }] },
            { "name": "SiteContact", "key": { "propertyRef": { "name": "ContactID" } }, "property": [{ "name": "ContactID", "type": "Edm.Int32", "nullable": "false", "d4p1:StoreGeneratedPattern": "Identity" }, { "name": "StudySiteID", "type": "Edm.Int32", "nullable": "true" }, { "name": "FirstName", "type": "Edm.String", "fixedLength": "false", "maxLength": "50", "unicode": "true", "nullable": "true" }, { "name": "LastName", "type": "Edm.String", "fixedLength": "false", "maxLength": "50", "unicode": "true", "nullable": "true" }, { "name": "EmailAddress", "type": "Edm.String", "fixedLength": "false", "maxLength": "150", "unicode": "true", "nullable": "true" }, { "name": "ContactType", "type": "Edm.Self.ContactTypeEnum", "nullable": "false" }], "navigationProperty": { "name": "StudySite", "relationship": "Self.SiteContact_StudySite", "fromRole": "SiteContact_StudySite_Source", "toRole": "SiteContact_StudySite_Target" } }],
        "enumType": { "name": "ContactTypeEnum", "isFlags": "false", "underlyingType": "Int32", "member": [{ "name": "PrimaryInvestigator", "value": "0" }, { "name": "StudyCoordinator", "value": "1" }, { "name": "ShippingContact", "value": "2" }, { "name": "CRA", "value": "3" }, { "name": "RecruitmentSpecialist", "value": "4" }, { "name": "Other", "value": "5" }] },
        "association": [{ "name": "SiteContact_StudySite", "end": [{ "role": "SiteContact_StudySite_Source", "type": "Edm.Self.SiteContact", "multiplicity": "*" }, { "role": "SiteContact_StudySite_Target", "type": "Edm.Self.StudySite", "multiplicity": "0..1" }], "referentialConstraint": { "principal": { "role": "SiteContact_StudySite_Target", "propertyRef": { "name": "SiteID" } }, "dependent": { "role": "SiteContact_StudySite_Source", "propertyRef": { "name": "StudySiteID" } } } }, { "name": "StudySite_Study", "end": [{ "role": "StudySite_Study_Source", "type": "Edm.Self.StudySite", "multiplicity": "*" }, { "role": "StudySite_Study_Target", "type": "Edm.Self.Study", "multiplicity": "0..1" }], "referentialConstraint": { "principal": { "role": "StudySite_Study_Target", "propertyRef": { "name": "StudyID" } }, "dependent": { "role": "StudySite_Study_Source", "propertyRef": { "name": "StudyID" } } } }],
        "entityContainer": { "name": "CodeFirstContainer", "entitySet": [{ "name": "Studies", "entityType": "Self.Study" }, { "name": "StudySites", "entityType": "Self.StudySite" }, { "name": "SiteContacts", "entityType": "Self.SiteContact" }], "associationSet": [{ "name": "SiteContact_StudySite", "association": "Self.SiteContact_StudySite", "end": [{ "role": "SiteContact_StudySite_Source", "entitySet": "SiteContacts" }, { "role": "SiteContact_StudySite_Target", "entitySet": "StudySites" }] }, { "name": "StudySite_Study", "association": "Self.StudySite_Study", "end": [{ "role": "StudySite_Study_Source", "entitySet": "StudySites" }, { "role": "StudySite_Study_Target", "entitySet": "Studies" }] }] }
    }
}

1 个答案:

答案 0 :(得分:0)

事实证明,importMetadata需要一个用于cSpaceOSpaceMapping属性的数组,而我在开始尝试时,然后我意识到我没有正确格式化json。

因此,要刷新元数据脚本以进行全新导入: 1.从/ metadata复制和粘贴 2.删除第一个双引号和最后一个引号。 3.然后在整个字符串中替换所有 \“。 4.对于cSpaceOSpaceMapping对象,将 \“替换为 \”

来自这样的元数据:

"{\"schema\":{\"namespace\":\"CodeFirstNamespace\",\"alias\":\"Self\",\"d4p1:UseStrongSpatialTypes\":\"false\",\"xmlns:d4p1\":\"http://schemas.microsoft.com/ado/2009/02/edm/annotation\",\"xmlns\":\"http://schemas.microsoft.com/ado/2009/11/edm\",\"cSpaceOSpaceMapping\":\"[[\\\"CodeFirstNamespace.Study\\\",\\\"MMG.Legacy.StudySiteComm.Core.Entities.Study\\\"],[\\\"CodeFirstNamespace.StudySite\\\",\\\"MMG.Legacy.StudySiteComm.Core.Entities.StudySite\\\"],[\\\"CodeFirstNamespace.SiteContact\\\",\\\"MMG.Legacy.StudySiteComm.Core.Entities.SiteContact\\\"]]\",\"entityType\":[{\"name\":\"Study\",\"key\":{\"propertyRef\":{\"name\":\"StudyID\"}},\"property\":[{\"name\":\"StudyID\",\"type\":\"Edm.Int32\",\"nullable\":\"false\",\"d4p1:StoreGeneratedPattern\":\"Identity\"},{\"name\":\"StudyName\",\"type\":\"Edm.String\",\"fixedLength\":\"false\",\"maxLength\":\"100\",\"unicode\":\"true\",\"nullable\":\"false\"},{\"name\":\"ClientName\",\"type\":\"Edm.String\",\"fixedLength\":\"false\",\"maxLength\":\"100\",\"unicode\":\"true\",\"nullable\":\"false\"}],\"navigationProperty\":{\"name\":\"StudySites\",\"relationship\":\"Self.StudySite_Study\",\"fromRole\":\"StudySite_Study_Target\",\"toRole\":\"StudySite_Study_Source\"}},{\"name\":\"StudySite\",\"key\":{\"propertyRef\":{\"name\":\"SiteID\"}},\"property\":[{\"name\":\"StudyID\",\"type\":\"Edm.Int32\",\"nullable\":\"true\"},{\"name\":\"SiteID\",\"type\":\"Edm.Int32\",\"nullable\":\"false\",\"d4p1:StoreGeneratedPattern\":\"Identity\"},{\"name\":\"ClientID\",\"type\":\"Edm.String\",\"fixedLength\":\"false\",\"maxLength\":\"12\",\"unicode\":\"true\",\"nullable\":\"false\"}],\"navigationProperty\":[{\"name\":\"Contacts\",\"relationship\":\"Self.SiteContact_StudySite\",\"fromRole\":\"SiteContact_StudySite_Target\",\"toRole\":\"SiteContact_StudySite_Source\"},{\"name\":\"Study\",\"relationship\":\"Self.StudySite_Study\",\"fromRole\":\"StudySite_Study_Source\",\"toRole\":\"StudySite_Study_Target\"}]},{\"name\":\"SiteContact\",\"key\":{\"propertyRef\":{\"name\":\"ContactID\"}},\"property\":[{\"name\":\"ContactID\",\"type\":\"Edm.Int32\",\"nullable\":\"false\",\"d4p1:StoreGeneratedPattern\":\"Identity\"},{\"name\":\"StudySiteID\",\"type\":\"Edm.Int32\",\"nullable\":\"true\"},{\"name\":\"FirstName\",\"type\":\"Edm.String\",\"fixedLength\":\"false\",\"maxLength\":\"50\",\"unicode\":\"true\",\"nullable\":\"true\"},{\"name\":\"LastName\",\"type\":\"Edm.String\",\"fixedLength\":\"false\",\"maxLength\":\"50\",\"unicode\":\"true\",\"nullable\":\"true\"},{\"name\":\"EmailAddress\",\"type\":\"Edm.String\",\"fixedLength\":\"false\",\"maxLength\":\"150\",\"unicode\":\"true\",\"nullable\":\"true\"},{\"name\":\"ContactType\",\"type\":\"Edm.Self.ContactTypeEnum\",\"nullable\":\"false\"}],\"navigationProperty\":{\"name\":\"StudySite\",\"relationship\":\"Self.SiteContact_StudySite\",\"fromRole\":\"SiteContact_StudySite_Source\",\"toRole\":\"SiteContact_StudySite_Target\"}}],\"enumType\":{\"name\":\"ContactTypeEnum\",\"isFlags\":\"false\",\"underlyingType\":\"Int32\",\"member\":[{\"name\":\"PrimaryInvestigator\",\"value\":\"0\"},{\"name\":\"StudyCoordinator\",\"value\":\"1\"},{\"name\":\"ShippingContact\",\"value\":\"2\"},{\"name\":\"CRA\",\"value\":\"3\"},{\"name\":\"RecruitmentSpecialist\",\"value\":\"4\"},{\"name\":\"Other\",\"value\":\"5\"}]},\"association\":[{\"name\":\"SiteContact_StudySite\",\"end\":[{\"role\":\"SiteContact_StudySite_Source\",\"type\":\"Edm.Self.SiteContact\",\"multiplicity\":\"*\"},{\"role\":\"SiteContact_StudySite_Target\",\"type\":\"Edm.Self.StudySite\",\"multiplicity\":\"0..1\"}],\"referentialConstraint\":{\"principal\":{\"role\":\"SiteContact_StudySite_Target\",\"propertyRef\":{\"name\":\"SiteID\"}},\"dependent\":{\"role\":\"SiteContact_StudySite_Source\",\"propertyRef\":{\"name\":\"StudySiteID\"}}}},{\"name\":\"StudySite_Study\",\"end\":[{\"role\":\"StudySite_Study_Source\",\"type\":\"Edm.Self.StudySite\",\"multiplicity\":\"*\"},{\"role\":\"StudySite_Study_Target\",\"type\":\"Edm.Self.Study\",\"multiplicity\":\"0..1\"}],\"referentialConstraint\":{\"principal\":{\"role\":\"StudySite_Study_Target\",\"propertyRef\":{\"name\":\"StudyID\"}},\"dependent\":{\"role\":\"StudySite_Study_Source\",\"propertyRef\":{\"name\":\"StudyID\"}}}}],\"entityContainer\":{\"name\":\"CodeFirstContainer\",\"entitySet\":[{\"name\":\"Studies\",\"entityType\":\"Self.Study\"},{\"name\":\"StudySites\",\"entityType\":\"Self.StudySite\"},{\"name\":\"SiteContacts\",\"entityType\":\"Self.SiteContact\"}],\"associationSet\":[{\"name\":\"SiteContact_StudySite\",\"association\":\"Self.SiteContact_StudySite\",\"end\":[{\"role\":\"SiteContact_StudySite_Source\",\"entitySet\":\"SiteContacts\"},{\"role\":\"SiteContact_StudySite_Target\",\"entitySet\":\"StudySites\"}]},{\"name\":\"StudySite_Study\",\"association\":\"Self.StudySite_Study\",\"end\":[{\"role\":\"StudySite_Study_Source\",\"entitySet\":\"StudySites\"},{\"role\":\"StudySite_Study_Target\",\"entitySet\":\"Studies\"}]}]}}}"

并且应该像这样结束:

{ "schema": { "namespace": "CodeFirstNamespace", "alias": "Self", "d4p1:UseStrongSpatialTypes": "false", "xmlns:d4p1": "http://schemas.microsoft.com/ado/2009/02/edm/annotation", "xmlns": "http://schemas.microsoft.com/ado/2009/11/edm", "cSpaceOSpaceMapping": "[[\"CodeFirstNamespace.Study\",\"MMG.Legacy.StudySiteComm.Core.Entities.Study\"],[\"CodeFirstNamespace.StudySite\",\"MMG.Legacy.StudySiteComm.Core.Entities.StudySite\"],[\"CodeFirstNamespace.SiteContact\",\"MMG.Legacy.StudySiteComm.Core.Entities.SiteContact\"]]", "entityType": [{ "name": "Study", "key": { "propertyRef": { "name": "StudyID" } }, "property": [{ "name": "StudyID", "type": "Edm.Int32", "nullable": "false", "d4p1:StoreGeneratedPattern": "Identity" }, { "name": "StudyName", "type": "Edm.String", "fixedLength": "false", "maxLength": "100", "unicode": "true", "nullable": "false" }, { "name": "ClientName", "type": "Edm.String", "fixedLength": "false", "maxLength": "100", "unicode": "true", "nullable": "false" }], "navigationProperty": { "name": "StudySites", "relationship": "Self.StudySite_Study", "fromRole": "StudySite_Study_Target", "toRole": "StudySite_Study_Source" } }, { "name": "StudySite", "key": { "propertyRef": { "name": "SiteID" } }, "property": [{ "name": "StudyID", "type": "Edm.Int32", "nullable": "true" }, { "name": "SiteID", "type": "Edm.Int32", "nullable": "false", "d4p1:StoreGeneratedPattern": "Identity" }, { "name": "ClientID", "type": "Edm.String", "fixedLength": "false", "maxLength": "12", "unicode": "true", "nullable": "false" }], "navigationProperty": [{ "name": "Contacts", "relationship": "Self.SiteContact_StudySite", "fromRole": "SiteContact_StudySite_Target", "toRole": "SiteContact_StudySite_Source" }, { "name": "Study", "relationship": "Self.StudySite_Study", "fromRole": "StudySite_Study_Source", "toRole": "StudySite_Study_Target" }] }, { "name": "SiteContact", "key": { "propertyRef": { "name": "ContactID" } }, "property": [{ "name": "ContactID", "type": "Edm.Int32", "nullable": "false", "d4p1:StoreGeneratedPattern": "Identity" }, { "name": "StudySiteID", "type": "Edm.Int32", "nullable": "true" }, { "name": "FirstName", "type": "Edm.String", "fixedLength": "false", "maxLength": "50", "unicode": "true", "nullable": "true" }, { "name": "LastName", "type": "Edm.String", "fixedLength": "false", "maxLength": "50", "unicode": "true", "nullable": "true" }, { "name": "EmailAddress", "type": "Edm.String", "fixedLength": "false", "maxLength": "150", "unicode": "true", "nullable": "true" }, { "name": "ContactType", "type": "Edm.Self.ContactTypeEnum", "nullable": "false" }], "navigationProperty": { "name": "StudySite", "relationship": "Self.SiteContact_StudySite", "fromRole": "SiteContact_StudySite_Source", "toRole": "SiteContact_StudySite_Target" } }], "enumType": { "name": "ContactTypeEnum", "isFlags": "false", "underlyingType": "Int32", "member": [{ "name": "PrimaryInvestigator", "value": "0" }, { "name": "StudyCoordinator", "value": "1" }, { "name": "ShippingContact", "value": "2" }, { "name": "CRA", "value": "3" }, { "name": "RecruitmentSpecialist", "value": "4" }, { "name": "Other", "value": "5" }] }, "association": [{ "name": "SiteContact_StudySite", "end": [{ "role": "SiteContact_StudySite_Source", "type": "Edm.Self.SiteContact", "multiplicity": "*" }, { "role": "SiteContact_StudySite_Target", "type": "Edm.Self.StudySite", "multiplicity": "0..1" }], "referentialConstraint": { "principal": { "role": "SiteContact_StudySite_Target", "propertyRef": { "name": "SiteID" } }, "dependent": { "role": "SiteContact_StudySite_Source", "propertyRef": { "name": "StudySiteID" } } } }, { "name": "StudySite_Study", "end": [{ "role": "StudySite_Study_Source", "type": "Edm.Self.StudySite", "multiplicity": "*" }, { "role": "StudySite_Study_Target", "type": "Edm.Self.Study", "multiplicity": "0..1" }], "referentialConstraint": { "principal": { "role": "StudySite_Study_Target", "propertyRef": { "name": "StudyID" } }, "dependent": { "role": "StudySite_Study_Source", "propertyRef": { "name": "StudyID" } } } }], "entityContainer": { "name": "CodeFirstContainer", "entitySet": [{ "name": "Studies", "entityType": "Self.Study" }, { "name": "StudySites", "entityType": "Self.StudySite" }, { "name": "SiteContacts", "entityType": "Self.SiteContact" }], "associationSet": [{ "name": "SiteContact_StudySite", "association": "Self.SiteContact_StudySite", "end": [{ "role": "SiteContact_StudySite_Source", "entitySet": "SiteContacts" }, { "role": "SiteContact_StudySite_Target", "entitySet": "StudySites" }] }, { "name": "StudySite_Study", "association": "Self.StudySite_Study", "end": [{ "role": "StudySite_Study_Source", "entitySet": "StudySites" }, { "role": "StudySite_Study_Target", "entitySet": "Studies" }] }] } } }