user5260143
user5260143

Reputation: 1098

breeze: add item to array of complex-type

I have a breeze class in durandal-project. the class (called "employee") includes property of complex-type (named "mainData"). "main-data" include array of complex-type named "childrenList". the complex-type of the elements of the array named "childDTO". I accept the data from server (c#) and in the client-side (javascript) I want to add and remove items to the array. after that, I want to send the array with the changes to the server, for saving.

my question is: how can I add items to array of breeze?

here is my classes definitions:

employee:

         addEmployeeType(store);
    function addEmployeeType(store) {
        store.addEntityType({
            shortName: "EmployeeDTO",
            namespace: "myServer.Entities",
            autoGeneratedKeyType: AutoGeneratedKeyType.Identity,
            dataProperties: {
                Emp_no1: { dataType: DataType.Int32, isNullable: false, isPartOfKey: true },
                employeeBaseData: {
                    name: "employeeBaseData",
                    complexTypeName: "EmployeeBaseDTO:#myServer.Entities",
                    isNullable: false,
                    isPartOfKey: false
                },

                employeeMainData: {
                    name: "employeePersonalDetails",
                    complexTypeName: "EmployeePersonalDetailsDTO:#myServer.Entities",
                    isNullable: true
                }
        });
        store.registerEntityTypeCtor("EmployeeDTO", null, employeeInit);
    }

MainData:

    addEmployeeMainDataType(store);
    function addEmployeeMainDataType(store) {
        store.addEntityType({
            shortName: "EmployeeMainDataDTO",
            namespace: "myServer.Entities",
            isComplexType: true,
            dataProperties: {
                PermGroup: { dataType: DataType.Int32, isNullable: true, isPartOfKey: false },                   
                Expire_Date: { dataType: DataType.DateTime, isNullable: true, isPartOfKey: false },                  
                ChildrenList: { dataType: DataType.childDTO, isPartOfKey: false, isScalar: false }
            }

        });
        store.registerEntityTypeCtor("EmployeeMainDataDTO", null, null);
    }

child:

      addEmployeeChildType(store);
    function addEmployeeChildType(store) {
        store.addEntityType({
            shortName: "ChildDTO",
            namespace: "myServer.Entities",
            isComplexType: true,
            dataProperties: {
                name: { dataType: DataType.String, isNullable: true, isPartOfKey: false },            

                age: { dataType: DataType.Int32, isPartOfKey: false }
            }

        });
        store.registerEntityTypeCtor("ChildDTO", null, null);
    }

Upvotes: 0

Views: 1112

Answers (1)

PW Kad
PW Kad

Reputation: 14995

Complex types are different from Navigation Properties in that you can not specify a mapping between the two entities. A navigation property has a reference from each entity to the other, but you can't do this with complexTypes because they are a property of the parent entity and cannot be assigned to another entity or anything else.

Check the docs for more info - http://www.breezejs.com/documentation/complextype-properties

Check this answer for more details on how to attach complex types - What's the correct way to create an unbound instance of a complex type in breeze?

Upvotes: 1

Related Questions