I’m working on a project where a client has a couple of Line of Business (LOB) systems that need to be connected to SharePoint 2010.We’re using Business Connectivity Services (BCS) to integrate them with SharePoint.For extensibility and maintainability reasons, we’re using Windows Communication Foundation (WCF) to connect to the LOB systems, which usually involve some sort of database and then file repository.
One such LOB system involves what are essentially people and documents.People author documents and thus have documents associated with them.We’ve built one LOB connector to BCS to return occurrences and documents together as separate entities.Since they’re related, we need BCS to recognize this using an association.
There are numerous examples of connecting two entities together inside of a single LOB system using foreign keys online.However, most of these involve connections to a database, not WCF.The ones that do use WCF use a foreign key relationship to complete the connection in SharePoint Designer 2010.That’s all well and good, but there’s another, simpler, way to associate two entities, especially if there’s no foreign key relationship.Using the AttachmentAccessor association property, entities can be associated with each other without the need for foreign keys.This is the only way I’ve found to identify a many-to-many relationship such as this in BCS.
Creating this Association is just like creating any other association, however, it must be done in Visual Studio 2010.Unfortunately, WCF LOB systems can’t be edited in BDC Model Designer, BDC Method Details View, and BDC Explorer, so you’ll be writing the XML by hand.As a side note, if you create your entity model as a DotNetAssembly and, when finished, go in and change its type to Wcf, you can do most of this from the Visual Studio views.
AssociationGroups Tag
Once you have your LOB systems specified, you’ll need to add one tag to the Destination entity, one tag to the Source entity’s association method, and several attributes to the method’s identifier input.In this example, I have a Matter (basically a document) entity, which is associated with a Person entity.On the Destination entity (Matter in this case), you add an AssociationGroups tag to the Entity tag that contains the following:
<AssociationGroups>
<AssociationGroupName=“PersonToMattersAssociation“>
<AssociationReferenceEntityName=“Person_Search“EntityNamespace=“SearchBCS“AssociationName=“GetMattersForPerson“Reverse=“false“/>
</AssociationGroup>
</AssociationGroups>
You must specify the EntityName, EntityNamespace, AssociationName, and Reverse attributes on the AssociationReference tag.
Association Tag
On the Source entity’s association method, you must specify an Association tag inside the MethodInstances tag of the method.Association’s Name attribute must match the AssociationName attribute from the AssociationReference tag above.Here you need all of the following code, except DefaultDisplayName in the Association tag:
<MethodInstances>
<AssociationName=“GetMattersForPerson“Type=“AssociationNavigator“ReturnParameterName=“GetMattersForPerson“DefaultDisplayName=“Person Navigate Association“>
<SourceEntityName=“Person_Search“Namespace=“SearchBCS“/>
<DestinationEntityName=“Matter“Namespace=“SearchBCS“/>
</Association>
</MethodInstances>
ForeignIdentifier Tags
Finally, you need to identify the source entity’s identifier for the input to the method.This is done through the addition of the ForeignIdentifierAssociationEntityName, ForeignIdentifierAssociationEntityNamespace, and ForeignIdentifierAssociationName attributes on the input.Without these, BCS will throw an error stating that there is no identifier for the source entity.Here’s the example with the given attributes:
<ParameterDirection=“In“Name=“employeeId“>
<TypeDescriptorTypeName=“System.Int32“IdentifierName=“id“Name=“id“ForeignIdentifierAssociationEntityName=“Person_Search“ForeignIdentifierAssociationEntityNamespace=“SearchBCS“ForeignIdentifierAssociationName=“GetMattersForPerson“ />
</Parameter>
What does this give you?When you open the BCS profile page for the Source external content type, all of the associated Destination entities will appear along with any of the TypeDescriptors in the Destination entity’s definition:
Furthermore, when you search for the source entity, the destination entities will appear also, even if there’s no direct reference to the source in the exposed destination entity.