Note that there are some explanatory texts on larger screens.

plurals
  1. POBreeze create entity from existing one
    text
    copied!<p>I've been pounding my head for a few days now.</p> <p>Imagine you have a car sales management application. You sell different models. Your Car model has 50 properties. Just for the example, let's say that you want to sell Bugatti Veyron. Now, you just received 5 of those cars. So, I log in to my application, create first Bugatti Veyron with specific ID. Then I want to add 2nd one, but there is a problem - I would have to write down all of those properties again! I'd like to have a Copy button and I'd just change serial number, breeze would change ID and voila, two cars in there!</p> <p>For hack sake, at first I created this solution:</p> <pre><code>newCar(datacontext.createCar()); newCar().property1(oldCar().property1()); newCar().property2(oldCar().property2()); ... </code></pre> <p>it was ugly, and after I proved I can do it, of course, request for application was to make everything copyable - no way I would do that! There must be a copy somewhere. After digging a lot of things, even trying to change some stuff in breeze itself, I couldn't do something like:</p> <pre><code>manager.createEntity('Car', oldCar); </code></pre> <p>Now, latest solution is a bit more viable than first one, but still requires more code than I would want and is not as intuitive as it could be:</p> <pre><code> var newObject = {}; manager.metadataStore._structuralTypeMap[oldCar.entityType.name].dataProperties.forEach(function (singleProperty) { if (!singleProperty.isPartOfKey) newObject[singleProperty.name] = oldCar[singleProperty.name]; }); var newCar = manager.createEntity('Equipment', newObject); </code></pre> <p>Is there any other "cleaner" way of making a new Entity with exactly the same properties, but of course, different id?</p> <p>I should mention that Car entity has some ICollections in it, but this hack-ish solution ignores them which could be improved, but currently I handle that myself with a few .forEach loops.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload