Wind: incorporateComplexType into addEntityType with entityTypes collection

My .NET entity looks like this:

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; }
}

To create a client-side version in Breeze, I use the following code:

        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 }
            }
        });

Now, I have added a new server-side property:

public Passport Passport { get; set; }

defined as:

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

I am unsure how to add it to Breeze?

Update:

Is it possible to achieve this without using a getter property like this:

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

Are there any alternative ways to do this?

Answer №1

It appears that the Passport is considered a ComplexType by Breeze.
To integrate Passport as a property of Customer, you need to provide metadata defining the Passport type:

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}
    }
});

You can find more details about this process in the Metadata by Hand - In Depth section of the documentation, around midway through the page.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Does Somebody Possess a Fine Floating Tag?

Some time ago, I came across this floating label that I have been searching for ever since. I experimented with a few that appeared promising and initially worked well, but they ended up presenting their own issues. Some required the mandatory attribute f ...

Experiencing an unusual issue when attempting to add or remove a class

I have the following function that is used to initialize a widget. jQuery.fn.initPortlet = function( parent_component ,header , component ){ var o = $(this[0]) this.addClass("ui-widget ui-widget-content ui-corner-all") .find(h ...

Guide to streaming audio files using vue.js

I am attempting to incorporate an audio file into my vue.js project using the following code: import sound from '../../recordings/sound.mp4' const audio = new Audio(sound) audio.play() Although this method works perfectly fine, I have encounter ...

Ways to efficiently add numerous string elements to an array in JavaScript without encountering any errors

I have implemented a function to process a large array of strings (user names), checking for single quotes and pushing them into a new array before returning it. However, I recently encountered an issue as the number of users in the list has grown substan ...

Quick method to populate an array with elements

I need to populate an array with a large number of objects. Currently, my approach looks like this: let useVertices = []; const len = this.indices.length; for(let i = 0; i < len; i++){ let index = this.indices[i]*3; useVertices.push(new THREE.Ve ...

Arranging and moving list elements without the use of jQuery UI (or any jQuery libraries at all?)

I have been searching for a JavaScript plugin that offers the same functionality as jQuery UI Sortable, which is the ability to drag and drop items to reorder them. In my case, these items are <li> tags. I prefer not to use jQuery UI because it is h ...

Unable to show <LI> elements

I'm having trouble adding LI items to the #historial <UL> tag. Whenever the for loop is inside the function, the list displays with some elements duplicated. I believe the for loop should remain outside of the function. Could someone please he ...

After removing the timezone from the timestamp log, why is it now showing as one day behind?

Within my programming, I store a timestamp in the variable 'var timeStamp = finalData.obj.followers[0].timestp;', which currently outputs '2020-04-15T00:00:00.000Z.' To extract only the date and remove the time zone information, I util ...

Search for an element by its class name after adding it using the append

My current situation involves the following code: $('body').append("<div class='bar'></div>"); var trial = $('.bar'); I am unable to locate bar. What mistake have I made in this scenario? ...

What could be causing the issue of not being able to access an element visible in AngularJS Videogular?

I am currently working on integrating the videogular-subtitle-plugin with the most recent version of Videogular/AngularJS. As a newcomer to AngularJS, I believe there must be a simple solution that I am overlooking. My main challenge lies within a directi ...

Extraction of properties from an object in an ES6 class

How should object destructuring be properly applied for methods within ES6 classes? user.ts import { Request, Response } from "express"; export class User { constructor (){ Object.assign(this,{ root:this.root, get:this.get ...

A guide on rendering a JSON array received from a URL using AJAX in AngularJS

Upon receiving a JSON array from the following URL: , it appears like this:https://i.stack.imgur.com/1Xrf4.png Within my AngularJS controller, I have the following code: $('#example-1').DataTable({ "ajax" : 'http://blahblahbla ...

contrasts of mongo.linq versus c# linq

I'm curious to know if there are notable distinctions between MongoDB.Linq and C# Linq when the join mechanism is not in use. In my setup, MongoDB serves as the storage unit while the client-side application utilizes the C# Linq Driver. My goal is to ...

`Problem with event propagation`

I am dealing with propagation issues caused by a series of click events. The container's data is loaded via ajax, hence the need for the body on-click method. Below is the code: $(function () { $("body").on("click","#top-div",function(){ ...

How can I trigger HierarchicalDataSource.read() when the kendoDropDownList's change event is fired?

Currently, I am utilizing the treeview and HierarchicalDataSource features of KendoUI. Additionally, I have included a kendoDropDownList at the top of the page. Each time a user changes the value of the dropdown list, it triggers the 'change' eve ...

Is it better to set the language of Puppeteer's Chromium browser or utilize Apify proxy?

Looking to scrape a website for French results, but the site supports multiple languages. How can I achieve this? Is it best to configure Puppeteer Crawler launch options using args, like so: const pptr = require("puppeteer"); (async () => { const b ...

Guide on utilizing Chrome Push Notifications on an HTTP website

I'm looking to incorporate Chrome push notifications (GCM) on my HTTP site. I've read that it's typically only for HTTPS sites, but is there a workaround or sample code available for integrating push notifications on an HTTP site? I'm ...

The "body" object cannot be accessed in a post request made from an Express router

I am currently utilizing Express router functions to manage some POST requests. Client.js let data = { endpoint: "Blah Blah"; }; return fetch('/api/get-preferences/', { method: 'POST', headers: { 'Content-Type': & ...

Guide to populating a dropdown list using React

The dropdown in my form should be populated with the value of testType, but it's not displaying. I have checked the data being sent and it is correct, so I'm unsure why it's not showing up in the dropdown menu. I only want this to populate w ...

What exactly are AngularJS module dependencies and how do they work together?

After exploring the tutorial example provided on AngularJs's site ( here) (The main HTML appears to be quite minimal with only ng-view and ng-app=phonecatApp included) Within the app.js file, we find: var phonecatApp = angular.module('phoneca ...