Support inheritence in the object model
Inheritance is now available in Breeze 1.3.1.
We’re labeling this feature as beta for now, not because we expect the APIs to change in the future, but because we still only have a reasonably small set of test scenarios and need your feedback to determine if we’ve missed any important test cases.
Jacques Snyman commented
Looks like there is an issue when using TPH.
See this question on Stackoverflow:
@Anonymous - Don't know what you mean. Should work for any query, including `fetchEntityByKey`. Please post a prospective bug report on StackOverflow rather than User Voice; and please provide details so that we can repro. Thx.
Does this work for manager.fetchEntityByKey? Only seems to be pulling in fields from the base class when I inspect json traffic.
Great! I'll follow this up at Stackoverflow.
AdminAdmin (Product Manager, Breeze.js) commented
Thanks. We're investigating this now.
I've moved this to Stackoverflow so more people will be aware of the issue (and our answer):
In general, we use UserVoice for feature requests and StackOverflow for questions, bug reports, etc. Thanks again for bringing this to our attention,
Wow! Amazing how quickly you guys answered to this petition! Thanks a lot for this quick response!
However, trying out this new version of Breeze, we've hit a problem here. When trying to load the metadata, we get this error:
"Error: Metadata import failed for api/securitychart/Metadata; Unable to process returned metadata:Unable to locate a 'Type' by the name: Vehicle:#Project.Model.Entities"
Just for clarification, the entity "Vehicle" is the base type from which two other entities "Motorbike" and "Car" inherit.
We've digged up a bit through breeze's code and found that the JSON returned from the ContextProvider.Metadata() method returns the array of entityTypes in the following order:
And the error pops out when trying to parse then entity data for Motorbike.
Without having much idea what was going on, we guessed that the base class Vehicle was not available when trying to parse the metadata for Motorbike, so we manipulated the array to let it process first the base class Vehicle. After doing this, this error no longer appears, but there's a different one "bad navigation properties".
You think you guys could give us some clue about how to proceed from here?
Thank you very much for your effort!
@Martin Klemsa - Potentially good idea. because THIS particular User Voice item is close, please open a new UserVoice for this request.
Breeze already propagates to the derived classes any validation rule set on the EF server-side base model class (e.g., a [Required] of [MaxLength] on the base BillingDetail class).
@Sverre How about creating and assigning validators to properties present in the base class, so that multiple entity types share them?
Thank you very much!
Chris Moschini commented
Wow cool, thank you. Very useful.
Sverre Andreassen commented
I seem to have created some confusion with my statement that Breeze supports a simple form of inheritance today but not "Database Inheritance". I hope to have clarified that in this StackOverflow comment: http://stackoverflow.com/questions/16103214/breezejs-createentity-is-undefined/16125887#16125887
While we will do this, and soon, I'm not sure we're all talking about the same thing. "Inheritance" in this case means database inheritance. Of course the model on the server can inherit from a base class. "Database inheritance" means that data for an entity are either split across several tables or (as in TPH) occupy a slice of one table and are identified by a discrimination column. "Database inheritance" support implies "polymorphic" queries that can return entities of multiple types. Frankly, I think database inheritance is usually a design error, a dubious attempt to project object-orientation onto a relational database. I avoid it like the plague. But, hey, if that's what you folks mean ... and want ... will give you the rope to hang yourselves.
With inheritance implemented, Breeze will be our first choice for our projects. Without it, I am not sure that it will help us at all!
Sverre Andreassen commented
Discovering that inheritance is not supported was a major disappointment. It is an absolute show stopper in my project. Sorry, no Breeze for me.
Essential for any serious project
Yes, Breeze is a great tool, but the lack of support for inheritance are currently keeping it out of our toolbox.
Yes, we've just hit the same wall here. I wish you are working on it and it's coming. :)
Once a DB model gets a little complex, inheritances immediately appear. I think supporting inheritance in Breeze is a top priority!