If you want to display information in the SalesOrderDetail table that relates to a Contact, you can create a foreign keyless association between the Contact entity and SalesOrderDetail entity. For example, a SalesOrderDetail table does not have a foreign key that maps to a primary key in a Contact table. Create this kind of association when the source entity does not have a direct relationship with the destination entity. You can create an association without mapping identifiers to field type descriptors. Where contacts.ContactID = TempContactID _ Where orders.SalesOrderID = salesOrderID _ĭim contactList As IEnumerable(Of Contact) = _ (From orders In dataContext.SalesOrderHeaders _ Public Shared Function SalesOrderToContact(ByVal salesOrderID As Integer) As IEnumerable(Of Contact) IEnumerable contactList = from contacts in dataContext.Contacts Int TempContactID = (from orders in dataContext.SalesOrderHeaders public static IEnumerable SalesOrderToContact(int salesOrderID) The following example returns the contact that is related to the sales order.
" Initial Catalog=AdventureWorks Integrated Security=True")ĭim orderList As IEnumerable(Of SalesOrderHeader) = _įrom orders In dataContext.SalesOrderHeaders _Īdd code to the Association Navigator method of the destination entity that returns a source entity. New AdventureWorksDataContext("Data Source=" & ServerName & _ Public Shared Function ContactToSalesOrder(ByVal contactID As Integer) As IEnumerable(Of SalesOrderHeader)Ĭonst ServerName As String = "MySQLServerName"ĭim dataContext As AdventureWorksDataContext = _ "Initial Catalog=AdventureWorks Integrated Security=True") įrom orders in dataContext.SalesOrderHeaders public static IEnumerable ContactToSalesOrder(int contactID)Ĭonst string ServerName = "MySQLServerName" ĪdventureWorksDataContext dataContext = new AdventureWorksDataContext The following example returns the sales orders for a contact. To create a foreign key-based relationship between the Contact entity and SalesOrder entity, choose the ContactID identifier next to each of these fields.Īdd code to the Association Navigator method of the source entity that returns a collection of destination entities. Both type descriptors appear in the Association Editor. The SalesOrder entity returns a ContactID type descriptor as part of the return parameter of Finder or Specific Finder methods. For example, you might create a foreign key-based association between a Contact entity and a SalesOrder entity. To create a foreign key-based association, relate identifiers and type descriptors that share the same name and type. For example, a form in Outlook that enables a user to create a sales order that can display customers in a drop-down list or a list of sales orders in SharePoint that enables users to open a profile page for a customer. This relationship enables consumers of the model to provide an enhanced UI for their users.
You can create a foreign key-based association by relating an identifier in the source entity to type descriptors defined in the destination entity. You can create two types of associations in the BDC designer: foreign key-based associations and foreign keyless associations. For more information about each of these methods, see Supported Operations. You can also add other types of methods to support more advanced scenarios. You must add the code to each of these methods to return the appropriate information. An Association Navigation method in the destination entity enables consumers to retrieve the source entity that relates to a destination entity.
An Association Navigation method in the source entity enables consumers to retrieve a list of destination entities. You can add methods to the service class of an entity by selecting them in the Association Editor.īy default, the Association Editor adds an Association Navigation method to the source and destination entities. Association methodsĪpplications such as SharePoint business data web parts consume associations by calling methods in the service class of an entity. For more information, see How to: Create an association between entities. You can define the details of the association in the Association Editor. Create an associationĬreate an association by choosing the Association control in the Visual Studio Toolbox, choosing the first entity (called the source entity), and then choosing the second entity (called the destination entity). These methods can be consumed by SharePoint web parts, lists, or custom applications to display data relationships in a user interface (UI). Visual Studio generates methods that provide consumers of the model with information about each association. You can define relationships between entities in your Business Data Connectivity (BDC) model by creating associations.