Geeks With Blogs

News Ashraful Alam Joy

Create Your Badge

Ashraful Alam is a Software Architect, who has 8 years of professional experience in Software Development industry. This Bangladeshi national is involved with project management and development of several US based software projects from his country. Already he has managed and developed several software projects, which are being used by several users of different countries, such as USA, Canada, Australia, and Bangladesh. While developing and managing a team, he contains and maintains a set of well defined engineering practices developed by him and other online developer communities.

Due to his willingness to give effort to improve and share better software development practices, Ashraf has been awarded as “Most Valuable Professional” (MVP) in ASP.NET category by Microsoft since year 2007 multiple times, which is a rare honor and prestigious reorganization among the developers around the world.

Check his portfolio to know more about him and his works.


.NETTER Characters... Every part of your life is best, if you can know yourself and thus create your life like an artist!

When we define a custom business entity as an architecture for  a given project, one common issue arises that, how we will consider “Many to Many” relationships? As there is only one entity for each database table, “Many to Many” tables might not be a good choice to make a separate table for that, since this is basically a connector entity.
 
Case:
 
Database Simplest Samples – Northwind Employees

Entities: Employees, Territories, EmployeeTerritories, Region
One-to-One: Employees (EmployeeId, ReportsTo)
Description: one employee reports to another employee.
One-to-Many: Region, Territories (TerritoryId, RegionId)
Description: One region has many territories.
Many-to-Many: Employee, Territories, EmployeeTerritories (EmployeeId, TerritoryId)
Description: One employee belongs to many territories and one territory has many employees.
 
Solutions:
 
1. Create a single table for the m2m table.
2. Attach the CRUD methods of the m2m table, as static methods, to one of the o2m entity. A common convention can be  chosen to attachment, to consider that entity, which is created first. In our case this is author.
3. Attach the m2m primary key, in the “save” instance method (for instance or update) parameter.
4. We can use a collection of objects, in the another tables entity. For example, the employee class may contain a collection of territories or the territory entity may contain a collection of employee object. The save method will be responsible to update the m2m list.

Posted on Thursday, July 6, 2006 4:01 AM Architecture , Database , .NET | Back to top


Comments on this post: Custom Entity – Many 2 Many Table Issue

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Ashraf Alam | Powered by: GeeksWithBlogs.net