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

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

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

public

override void Execute()

{

try

 

 

{

// 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";

model.Contracts.Add(dataContract);

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

 

 

transaction.Commit();

}

}

}

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.


Zack

Developer
May 22, 2008 at 6:53 PM
Edited May 22, 2008 at 6: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]
dataContract.DataMembers.Add(dataType);
}}

 

 

 

 

May 23, 2008 at 10: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.

Zack
May 23, 2008 at 11:50 AM

Ok,

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

 

WCFDataElement

dc = new WCFDataElement();

dc.IsRequired = true;

dc.Order = 5;

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

dataType.ObjectExtenderContainer.ObjectExtenders.Add(dc);

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

Thanks

Zack

May 23, 2008 at 1:42 PM
Ok,

The aggregations are pretty easy to as it turns out;

AggregationConnectionBuilder

.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.

Great.