Skip to main content

Cloud

Business Connectivity Services: AttachmentAccessor Associations Using Windows Communication Foundation from Line of Business Systems

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_SearchEntityNamespace=SearchBCSAssociationName=GetMattersForPersonReverse=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=GetMattersForPersonType=AssociationNavigatorReturnParameterName=GetMattersForPersonDefaultDisplayName=Person Navigate Association>

<SourceEntityName=Person_SearchNamespace=SearchBCS/>

<DestinationEntityName=MatterNamespace=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=InName=employeeId>

<TypeDescriptorTypeName=System.Int32IdentifierName=idName=idForeignIdentifierAssociationEntityName=Person_SearchForeignIdentifierAssociationEntityNamespace=SearchBCSForeignIdentifierAssociationName=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.

Tags

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Andrew Schwenker

Andrew Schwenker is a Sr. Technical Consultant within Perficient’s Microsoft National Business Unit East's SharePoint practice. Andrew has nearly 2 years of experience in consulting and has participated in projects that have touched nearly every aspect of SharePoint 2010. Andrew earned his Bachelor’s degree in Computer Science as well as Master’s degrees in Computer Science and Information Systems from Indiana University. He’s interested in creating winning solutions to generate business innovation using SharePoint. Prior to starting at Perficient, Andrew completed internships with General Electric, ExactTarget, and Great American Financial Resources. During his studies, he actively participated in Alpha Phi Omega National Service Fraternity and competed in the first annual Cluster Challenge at SC07 in Reno, NV. Andrew was a part of the dynamic PointBridge team that was acquired by Perficient.

More from this Author

Follow Us