HOL - convert importing Service, to importing datacontact from business entity.

Topics: Service Factory Modeling Edition Forum
May 22, 2008 at 5:25 PM
Edited May 22, 2008 at 5:26 PM

I have done the HOL and got this bit of code working.


override void Execute()






// To interact with a store, we need to be in the context of a Transaction.



using (Transaction transaction = DataContractStore.TransactionManager.BeginTransaction("ImportEntity"))


// From the store, retrieve the ServiceContractModel, this is the element that contains all other elements in this model.



DataContractModel model = DomainModelHelper.GetElement<DataContractModel>(this.DataContractStore);

if (model != null)


DataContract dataContract = (DataContract)DataContractStore.ElementFactory.CreateElement(DataContract.DomainClassId);

dataContract.Name = "MyNewContractFromEntity";


// Committing the transaction will update the model and draw the appropriate shapes to the diagram.







catch (InvalidOperationException invalidOperation)


// If something went wrong during execution, notify the user.



IUIService uiService = this.GetService<IUIService>();

uiService.ShowError(invalidOperation, "Importing the Entity did not complete successfully.");



Does anyone know how I would create and set up the properties on the DataContract's members such as the type, isnullable etc etc?

Thanks any help.


May 22, 2008 at 7:53 PM
Edited May 22, 2008 at 7:57 PM

These properties are part of a "PrimitiveDataType" that is in turn a DataMember element that you can find in the dataContract.DataMembers collection. In your case, you may add new PrimitiveDataType and set its values like this:
PrimitiveDataType dataType = store.ElementFactory.CreateElement(PrimitiveDataType.DomainClassId) as PrimitiveDataType;
dataType.IsNullable = true;
dataType.Type = [some type]





May 23, 2008 at 11:51 AM
Hi Charlyfriend,

Thanks for that it works great.

How would I access properties for shapes that are in Extenders?  And have you managed to add aggregators to take care of joining collections etc?

Many thanks for your help.

May 23, 2008 at 12:50 PM


Work that one out, this seems to work although I have not tested it end to end yet;



dc = new WCFDataElement();

dc.IsRequired = true;

dc.Order = 5;

dataType.ObjectExtenderContainer = new Microsoft.Practices.Modeling.ExtensionProvider.Extension.ObjectExtenderContainer();


So now I just need to work out how to use the Aggregators, then I should be ok.



May 23, 2008 at 2:42 PM

The aggregations are pretty easy to as it turns out;


.Connect(dataContractSource, dataContract, "MyTestCollection");

DataMember myDm = dataContract.DataMembers.Find(

delegate(DataMember d)


if (d.Name == "MyTestCollection") { return true; }

return false;


myDm.CollectionType = typeof(List<>);

So I should now be able to build my contracts by importing them from an external resource.