About

SubSonic is a .net open source project developed by Rob Conery and a core team of developers including Eric Kemp, Scott Watermasysk, Jon Galloway, Phil Haack, and Gavin Joyce. The current stable release is version 2.0.3. Nightly builds are available in our SVN respository.

Tags

ManyManyList

Getting data in and out of a Many To Many join table can be tedious and take a ton of time. This control can hopefully help you save a little..

 

This is a checkbox list that helps you to admin many to many relationships in your database. For this to work, you need to specify a mapTableName (in other words, the joining table), a primaryTableName (in other words the table with the primaryKey from which you're working), a primaryKeyValue, and the foreignTableName (the other end of the many to many from the primaryTableName).

If, in Northwind, there was a many to many between Products and Categories with a table called "ProductCategoryMap", and you wanted to use this control from a product's page, you would declare it like this:

<subsonic:ManyManyList id=MrManyMapper runat=server primaryTableName="Products" foreignTableName="Categories" mapTableName="ProductCategoryMap" primaryKeyValue="5">


This would generate a CheckBoxList of all Categories, and would then check off all the categories for the Product with ID 5.

When you want to save the information, you simply call (in code): "MrManyMapper.Save()". This will save all the checked bits to the mapping table, within a transaction.

Again, we only query two columns here - the primaryKey and descriptor for the foreignTable

Subscribe