I'd like to know if it's mandatory to use DataAnnotations for breezejs ef metadata provider to properly get all configurations for each entity? Alternatively, can one avoid the use of any conventions or data annotations and instead configure a mapping class for each entity with explicit mappings and configurations?
You have several options:
1) You can define the metadata yourself on either the client or server, instead of having it generated from EF metadata. See the Breeze Metadata discussion here
2) You can define this same metadata on the client. See the MetadataStore addEntityType method.
3) Along with either of the two options above, you can 'reinterpret' any json results returned from any web service call with the JsonResultsAdapter. We will have an example of this out within the next week or so. By default, this is done for you, but you can intercept the process.
4) Hybrid use, where some entities are defined via metadata from the server and some from client side metadata are also possible. Similarly, you can choose to implement a JsonResultsAdapter for just selected queries and use the default for the rest.
Hope this helps.
Related
We are building a RESTful web service where there are sometimes different required fields for a POST than a PUT. For example, a field like CustomerSinceDate is allowed to be set on an insert, but not on an update. Is there is a way to set that up with Data Annotations?
EntityFramework does not (and should not) know anything about your web service. It deals only with what rules exist in the persistence layer.
What you are looking for is validation.
So in your REST service, you should check whether CustomerSinceData has been changed, and the entity is being updated. If so, you should throw an Exception with an appropriate message to the consumer.
Here is an article on writing your own DataAnnotations, if you prefer using those:
http://msdn.microsoft.com/en-us/data/jj819164#attributes
Otherwise, take a look at this article on how to write your own custom validation: http://msdn.microsoft.com/en-us/data/gg193959.aspx
(in particular, the section on IValidatableObject).
Your rule could be formulated as (pseudo code)
//if object exists in db AND CustomerSinceData has changed
DataAnnotations will get you a long way, but can be tedious to write if you are writing business logic that will never be reused anywhere else.
In our entity framework model that identify the customer, a simple Customer_GUID. We are using breeze with asp.net mvc and doing IQueryable.
Is there a way to globally not return those columns in the JSON? This would reduce a good bit of data coming across the wire. We don't want to remove it from mapping in our EF model because we still use it when we save.
You might want to look at the Json.NET documentation in particular the [JsonIgnore] attribute. Look at "Conditional Property Serialization" for more sophisticated scenarios.
Do be careful about insert and update data coming from the client. You'll have to do something if your client uploads a new entity for insertion and it lacks the properties you require on the server side.
To be clear, your configuration of Json.NET has no affect on your server-side EF model ... exactly what you wanted.
That also means that metadata generated from your EF model will describe properties the client can't see. You'll want to compensate for that I imagine. Such compensation is beyond the scope of this question; look to the Breeze documentation on metadata ... particularly "Metadata by hand" and "EF as a design tool".
How (or can) I specify programmatically which validation group OpenJPA should validate against during a persist or merge operation? Is this option only available via persistence.xml?
I'm drawing a blank.
Thanks.
The groups are configured per entity manager factory. If you obtain your entity manager factory programmatically via Persistence#createEntityManagerFactory() you can pass the groups to be validated during lifecycle validation using the properties javax.persistence.validation.group.{pre-persist|pre-update|pre-remove} but there is no (standardized) way for specifying the groups on a per-operation basis.
Yes, configuration is only via persistence.xml. I guess it would be open for JPA implementations to provide implementation specific ways, but that's not standardized. I am not sure whether OpenJPa offers such a provider specific option, but I don't think so.
So far i understand that i will have no more need to define an #version field in my entitites and no more need to use an entity locator. And for value proxies i will have to usenormal editors. Any other diffrences, advantages, disadvantages? What about in the context of using request factory in conjunction with spring
The main difference is that with EntityProxy, the client can send a diff of changes rather than the entire object graph. This is made possible because EntityProxys have an identity, so the server can fetch the identity from the datastore and then apply the diff/patch sent from the client, and only then the entity will be passed to your service methods.
With ValueProxy you basically have an equivalent of GWT-RPC: the object is reconstructed from scratch on the server, and not associated with your datastore (in the case of JPA for instance, it's not attached to the session). Depending on your datastore API, this can make things more complex to handle in your service methods.
Other than that, you'll also lose the EntityProxyChange events.
I've got Doctrine 2 set up on Zend Framework 1.10 and have all the autoloading set up correctly including all necessary config settings in the application.ini. What I need to do now (or so I believe) is to create my Entity classes with mapping information so that the entity manager can work with my database.
What I don't want to do is write the Entity classes by hand as this will take ages but I can't seem to work out what to do next. Does the command line tool have functionality to create the entities, proxies and all other necessary classes from an existing schema?
You can use the reverse engineering tool of Doctrine http://www.doctrine-project.org/docs/orm/2.0/en/reference/tools.html#reverse-engineering
But it also doesnt detect everything as noted in the reference.
Your best bet is to reverse engineer and filling the rest with manually IMO.
Using the command line tool:
./bin/doctrine orm:convert-mapping --from-database xml ./bin/tmp
This will generate your xml mappings. Then, ensure that when configuring Doctrine CLI tool you change the driver to the XmlDriver
$driver = new \Doctrine\ORM\Mapping\Driver\XmlDriver(array(
APPLICATION_PATH . '/../bin/tmp'
));
$config->setMetadataDriverImpl($driver);
My CLI configuration uses Zend_Application, so I'm usually changing this in my Bootstrap.
Now run
./bin/doctrine orm:generate-entities ./bin/tmp
The Xml Metadata Driver is required in order for orm:generate-entities to convert from xml to entities. If you use the Default Annotation Driver, it will convert entities in the annotation driver path to entities which is not what we want here.