Breeze:addEntityType 和 complexType(entityTypes 聚合)

Breeze: addEntityType with complexType (entityTypes aggregation)

我有 .NET 实体:

public class Customer
{
    public long Id { get; set; }
    public string FirstName { get; set; }
    public string MiddleName { get; set; }
    public string LastName { get; set; }
    public DateTime BornOn { get; set; }        
    public string RegisteredAddress { get; set; }
    public string ResidentalAddress { get; set; }
}

我使用此代码在 Breeze 中创建客户端模拟:

        store.addEntityType({
            shortName: 'Customer',
            namespace: 'ClientSide.App',
            dataProperties: {
                id: { dataType: types.long, isNullable: false, isPartOfKey: true },
                firstName: { dataType: types.string },
                middleName: { dataType: types.string },
                lastName: { dataType: types.string },
                bornOn: { dataType: types.datetime },
                registeredAddress: { dataType: types.string },
                residentalAddress: { dataType: types.string },
                lastNameWithInitials: { dataType: types.string },
                phone: { dataType: types.string },
                mobilePhone: { dataType: types.string },
                email: { dataType: types.string }
            }
        });

现在,我有新的服务器端 属性:

public Passport Passport { get; set; }

public class Passport
{
    public string Series { get; set; }
    public string Number { get; set; }
    public DateTime IssuedOn { get; set; }
    public string IssueAuthority { get; set; }
}

我不知道如何将它添加到 Breeze 中?

更新:

如果没有 getter 属性 可以这样吗:

public string Phone
    {
        get
        {
            var contact = Contacts.FirstOrDefault(c => c.Type == ContactType.Phone);
            return contact != null ? contact.Value : "";
        }
    }

还有其他方法吗?

看起来 Passport 是 Breeze 所说的 ComplexType
您应该添加描述 Passport 类型的元数据,然后将其添加为 属性 of Customer:

    store.addEntityType({
        shortName: 'Passport',
        namespace: 'ClientSide.App',
        isComplexType: true,
        dataProperties: {
            series: { dataType: types.string },
            number: { dataType: types.string },
            issuedOn: { dataType: types.datetime },
            issueAuthority: { dataType: types.string }
        }
    });

    store.addEntityType({
        shortName: 'Customer',
        namespace: 'ClientSide.App',
        dataProperties: {
            id: { dataType: types.long, isNullable: false, isPartOfKey: true },
            firstName: { dataType: types.string },
            // ... other properties ...
            passport: { complexTypeName: "Passport", isNullable: false}
        }
    });

这在文档的 Metadata by Hand - In Depth 页面中有描述, 大约在页面的一半。