2014-09-09 3 views
0

AngularJs와 함께 BreezeJs를 사용하여 MongoDB 백엔드가있는 웹 API와 통신하고 있으며 상속성이있는 복잡한 유형의 배열이 필요한 문서 중 하나의 메타 데이터를 정의하는 데 문제가 있습니다.BreezeJs - 상속 메타 데이터가있는 복합 유형의 배열

이는 MongoDB의 문서

{ 
    "_id" : ObjectId("53f2f0f117166f1e6898cc32"), 
    "Name" : "SectionContainer1", 
    "Sections" : [{ 
    "_t" : "SectionA", 
    "Title" : "sdf sdaf dsfsdfdsfsdfds" 
    }, { 
    "_t" : "SectionB", 
    "Title" : "sdf sdaf dsfsdfdsfsdfds" 
    }, { 
    "_t" : "SectionC", 
    "_id" : "53f38e1317166f196025849b", 
    "Title" : "sdf sdaf dsfsdfdsfsdfds" 
    }] 
} 

및 클래스 구조는

public class SectionContainer 
{ 
    public ObjectId Id{get;set;} 
    public string Name{get;set;} 
    public List<BaseSection> Sections{get;set;} 
} 

public class BaseSection 
{ 
    public string Title{get;set;} 
} 

public class SectionA : BaseSection 
{ 
    ... 
} 

public class SectionB : BaseSection 
{ 
    ... 
} 

public class SectionC : BaseSection 
{ 
    ... 
} 

이것은 내가 불행하게도 바람이하지 않는 것 BreezeJs

(function() { 
'use strict'; 

angular 
    .module('app') 
    .factory('metadataFactory', ['breeze', metadataFactory]); 

function metadataFactory(breeze) { 
    var addType, DATE, DT, helper, ID; 

    // The metadata definition service 
    return { 
     fillMetadataStore: fillMetadataStore 
    }; 

    /*** Implementation ***/ 
    function fillMetadataStore(metadataStore, serviceName) { 
     init(metadataStore, serviceName); 

     addTypes(); 
    } 

    function addTypes() { 
     addType({ 
      name: 'SectionContainer', 
      dataProperties: { 
       id: { isPartOfKey: true }, 
       name: { nullOk: true }, 
       sections: { complexTypeName: "BaseSection", hasMany: true } 
      } 
     }); 

     addType({ 
      name: 'BaseSection', 
      isAbstract: true, 
      isComplexType: true, 
      dataProperties: { 
       id: { isPartOfKey: true }, 
       title: { nullOk: true } 
      } 
     }); 

     addType({ 
      name: 'SectionA', 
      isComplexType: true, 
      baseTypeName: "BaseSection", 
      dataProperties: { 
       id: { isPartOfKey: true }, 
       title: { nullOk: true }, 
      } 
     }); 

     addType({ 
      name: 'SectionB', 
      isComplexType: true, 
      baseTypeName: "BaseSection", 
      dataProperties: { 
       id: { isPartOfKey: true }, 
       title: { nullOk: true }, 
      } 
     }); 

     addType({ 
      name: 'SectionC', 
      isComplexType: true, 
      baseTypeName: "BaseSection", 
      dataProperties: { 
       id: { isPartOfKey: true }, 
       title: { nullOk: true }, 
      } 
     }); 
    } 

    // Initialize the metdataFactory with convenience fns and variables 
    function init(metadataStore, serviceName) { 

     var store = metadataStore; // the metadataStore that we'll be filling 

     // 'Identity' is the default key generation strategy for this app 
     var keyGen = breeze.AutoGeneratedKeyType.Identity; 

     // Breeze Labs: breeze.metadata.helper.js 
     // https://github.com/IdeaBlade/Breeze/blob/master/Breeze.Client/Scripts/Labs/breeze.metadata-helper.js 
     // The helper reduces data entry by applying common conventions 
     // and converting common abbreviations (e.g., 'type' -> 'dataType') 
     helper = new breeze.config.MetadataHelper(namespace, keyGen); 
     helper.addDataService(store, serviceName); 

     // addType - make it easy to add the type to the store using the helper 
     addType = function (type) { return helper.addTypeToStore(store, type); }; 

     // DataTypes we'll be using 
     DT = breeze.DataType; 
     DATE = DT.DateTime; 
     ID = DT.Int32; 
    } 
    } 
})(); 

에서 할 노력하고 무엇인가 복잡한 유형의 상속을 허용하고 데이터가 MongoDB에서 포맷되는 방식으로 인해 e 섹션은 ​​자체 엔티티가 아닙니다. Breeze에서 이와 같은 데이터를 표현할 수 있습니까? 그렇다면 어떻게해야합니까? Breeze.js 워드 프로세서에서 촬영

답변

0

-

복합 유형 (바람에 키 속성) 정체성이없는, 따라서 독립적으로 존재할 수 없습니다. 복합 유형은 엔티티 유형 또는 기타 복합 유형의 특성으로 만 존재할 수 있습니다.

질문에 대답하기 위해 부모가 없으면 존재할 수 없습니다. 또한 유효하지 않은 복잡한 유형의 키를 설정할 수 없습니다. 이것이 Breeze뿐만 아니라 익숙한 유사한 시스템에서도 복잡한 유형의 특성입니다.

나는 대안이되었지만 몇 가지 문제를 발견 한 후에 문제가 있음을 알았고 내가 그렇지 않은 것을 알았습니까? 나는 그것을 전혀 도움이 있는지 확인하기 위해 명백한 지적 거라 생각 -

addType({ 
    name: 'BaseSection', 
    // I don't believe this is a valid property 
    isAbstract: true, 
    isComplexType: true, 
    dataProperties: { 
     // Complex types cannot have keys 
     id: { isPartOfKey: true }, 
     title: { nullOk: true } 
    } 
}); 

나는 당신이 사용하는 코드는 의사 코드 듯, 그래서 당신이 이미 알고 확신합니다. 이미 무엇을 필요 상속하는

  1. 이 모델 정의에서 서버의 엔티티를 정의하고 여전히 클라이언트에서 사용할 수있는 사용되지 않는 특성을 가지고 있지만 것 - 그 경우라면 나는 단지이 개 권고를 할 것이다 돌려 주어질 때까지는 null

  2. 복잡한 유형을 사용하는 대신 Breeze 요소를 사용하십시오. 사용하려고하는 모델이 올바른 방향 인 것처럼 보이지 않습니다. 물론 키 특성을 가질 수 없다는 것을 언급 할 때 언급 된 방향이 맞지만 제목 외에 유일한 특성입니다.당신은 항상 다시 부모 개체에 대한 참조를 가지고 다른 컬렉션만큼 그들이 같은 ID를 다시 사용하므로이 유효 할 수 -

    으로 AddType ({ 이름 : 'BaseSection', dataProperties : { ID : {type : ID}, 제목 : {nullOk : true} } });

    으로 AddType ({ 이름 : 'SectionA', dataProperties : { ID : {유형 : ID}, 제목 : {nullOk : TRUE} }, navigationProperties : { baseSection : 'BaseSection' } }});

여기서 문제는 바람이 SectionA의 속성 ID는 할 수 있지만, 당신은 내가 그 작업을 수행하는 방법에 익숙하지 않은 오전 사용이 속기 메타 데이터 형식을 제공하기 쉽습니다 BaseSection 일치해야 알 수 있도록해야 할 것입니다. 그 재산은 이렇게 보일 것입니다. -

"navigationProperties": [ 
    { 
     "name": "baseSection", 
     "entityTypeName": "BaseSection", 
     "isScalar": true, 
     "associationName": "SectionA_BaseSection" 
    }, 
]