0

I work in Durandal-project and use Breeze objects.

I have breeze model that contain some complex-types.

At server side, I set some of the complex-type properties to be null.

But, when object arrives to client-side, the complex-types which I have set to be null - contain referance to object of complex-type. I need them to be null.

my main model pattern:

     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
                },
                employeeTblData: {
                    name: "employeeTblData",
                    complexTypeName: "EmployeeTblDTO:#myServer.Entities",
                    isNullable: false
                },
                employeePersonalDetails: {
                    name: "employeePersonalDetails",
                    complexTypeName: "EmployeePersonalDetailsDTO:#myServer.Entities",
                    isNullable: true
                },               
                employeeContacts: {
                    name: "EmployeeJobsDTO",
                    complexTypeName: "EmployeeJobsDTO:#myServer.Entities",
                    isNullable: true
                }
            }

        });
        store.registerEntityTypeCtor("EmployeeDTO", null, employeeInit);
    }

server side code (c#, using apiController):

      if (!EnablJobsData)
                employeeData.employeeJobsData = null;

I want that when the condition is true, so at client side employeeData.employeeJobsData() - returns null. Actuality, it returns breeze complex-entity.

Thanks!

user5260143
  • 1,048
  • 2
  • 12
  • 36

1 Answers1

1

Right now all scalar breeze complex object properties are treated as nonnullable value types. This decision was made so that queries for subproperties on a complex object would not have to involve special null checking logic. i.e. so that we could use expressions like this:

myCustomer.address.city == 'Los Angeles";

instead of

myCustomer.address != null && myCustomer.address.city == 'Los Angeles';

Obviously this kind of expression would get even uglier for more deeply nested complex object properties.

The way this is handled internally is that each complex object has a 'null' version that is simply the complex object with all of its properties set to their default or null values. This null version is the default value for any unassigned complex object properties.

So if you want to detect a 'null' complex object you can simply add a method that checks for this condition.

Note that this is not an issue for properties that return arrays of complex objects. In this case an empty array is a valid construct.

Jay Traband
  • 17,053
  • 1
  • 23
  • 44