I am trying to add contraints to my ecore metamodel using ocl. I could add the invariants using the OclInEcore editor. But, I want to add as a separate complete ocl file. I am confused how to do this. I created a separate ocl file and while creating the model instance, I can load this file and do the validating. But I dont want the user do this step.
I want the validation embedded in the autogenerated model editor tool.
I am not sure why you have asked the same question under three different titles. Perhaps the Forum is playing up again ....
It seems you have found both ways to work. The OCL tooling generation uses an MWE2 script for auto-generation and one of the steps is a merge of Pivot.ecore and Pivot.ocl so that they are generated as if written as an OCLinEcore file.
The relevant internal code is in org.eclipse.ocl.examples.build.utilities.ConstraintMerger. Unfortunately provision of a friendly public API is one of many outstanding Bugzillas .
The extensibility of the merge has been debugged in M4 so that QVTd *.ecore and *.ocl are merged too. Quite a few bugs and stupidities were rectified, so look at the latest GIT code, not at the Neon releases.