many-to-many

c# - what collection type is recommended for self-referential many-to-many model?

Hi, What type of collection would be best in C# to implement the following requirements do you think? Need to model web file (e.g. class = "webfile"), so one class only preferred Model parent & child relationship - In terms of associations a webfile can have multiple child webfiles, and child webfiles can have multiple parents. (thin...

NHibernate many-to-many using foreign key different to primary key

When creating a one-to-many relationship in NHibernate it is possible to use the "property-ref" attribute to specify that the relationship occurs on a different column to the primary key. This is sometimes useful for legacy databases. It seems that the same feature should be available for many-to-many relationships, but I can't find it ...

How to model many-to-many relationships in plain C#?

First of all I am making it clear that, I am not using any OR Mapper framework to solve this problem, coz I need to understand the model from the ground up. OK. Let's see the table designs: Course - table ------------------ ID | CourseName ------------------ 1 | C++ 2 | Java ------------------ Teacher - table ---------------...

Can't insert entries of a many-to-many relationship in Entity Framework in a specific order

Hello, I have a many-to-many relationship between 2 entities in Entity Framework, like here . So, Employees and Projects. At one point, I would like to insert some Projects to a Employees entity in a specific order. By conserving the order I would like to know which was the first preference of the Employees for a Projects entity. The th...

nhibernate many-to-many bag not inserting in the association table.

I know this has been asked and answered a number of times, but I have two classes that are many-to-many. I've reciprocal mapped them using bags. Here is the NHibernate Mapping: Calendar: <?xml version="1.0" encoding="utf-8"?> <!--Generated by NHibernate.Mapping.Attributes on 2009-10-09 18:09:29Z.--> <hibernate-mapping xmlns="urn:nhibe...

Algorithm that searches for related items based on common tags

Lets take StackOverflow questions as example. Each of them has multiple tags assigned. How to build an algorithm that would find related questions based on how many common tags they have (sorted by number of common tags)? For now I can't think about anything better than just selecting all questions that have at least one common tag into...

NHibernate: How to automatically delete many-to-many associations (cascade)

In my database I've got Users and UserGroups which have a many-to-many relation. The User has a set of UserGroup, the UserGroup domain object does not see the User. <class name="User" table="UserTable"> <set name="UserGroup" cascade="save-update" access="field.pascalcase-underscore" table="User2UserGroup"> <key column="User_...

Fluent nHhibernate gets but fails to save with 'HasManyToMany'

I have a Resource entity which has a many-to-many relationship with a File entity, such that a resource can reference multiple files and a file can reference multiple resources. Now I expect the save to cascade down from the Resource to the File entities when the Resource is Saved - When I load a Resource entity it is loading the File e...

List<T> item remove problem.

Don't be scared of the extensive code. The problem is general. I just provided the code to understand the problem better. I am trying to find out a standard approach of manipulating tables with many-to-many relationships. And I am almost done. Here Teacher and Course have M:M relationship. I have designed my classes as follows: Teacher...

NHIBERNATE: How to map a collection into the DB using Mapping.Attributes

I Have this Product Class i took from the examples of how to use nhibernate (but i did some modifications to it) I want to be able to map a class and all of it's references into the DB. [NHibernate.Mapping.Attributes.Class(Lazy=true)] public class Product { [NHibernate.Mapping.Attributes.Id(Name="Id",TypeTyp...

How do I filter an entity based on another entity? Linq many-to-many in C#.

This is easy to do in SQL and I'm having a very hard time achieving this using Linq to SQL. I have two entities setup, Project and ProjectsbyUser: [Table(Name = "Projects")] public class Project { [Column(IsPrimaryKey = true, IsDbGenerated = true, Name="Job")] public string ProjectId { get; set; } [Column(Name = "Descript...

Nhibernate change from lazy=false to fetch=join many-to-many

i have: <bag name="Categories" table="CMS_Articles_Categories" lazy="true"> <key column="article_id"/> <many-to-many class="Framework.CMS.Domain.Category, Framework.CMS" column="category_id"/> </bag> This is under an Article mapping. An article can be in many categories and of course a category has many articles. When this is ...

How should I architect this with Ruby on Rails?

Sorry for the vague title, but this is kind of hard to put into one line. I have a database full of contact information, and I want to be able to put those different contacts into groups which will also be stored in the database. So, maybe I have 2 groups, "coworkers" and "neighbors", I want to be able to see a list of all my contacts...

GUI patterns to edit data with many-to-many relationship

Hi, I often run into a situation where I need to come up with a GUI to edit data that has a n:m relationship. I'm looking for user friendly GUI ideas. [table1] | /|\ [table2] \|/ | [table3] Usually the GUI resembles something like this: Grid that shows all items from table1 Add table3 item... (shows modal window with t...

NHibernate many-to-many with non ID fields

Hi, I have a table A containing items with : - an identity key - a non-nullable custom hash (generated on my own) I have a table B containing documents with : - an identity key. I have a table C containing documents slots with : - an identity key - a foreign key to table B (document) - a nullable custom hash (so table A is implicitly ...

what's the best way to represent a many-to-many relationship in a database?

If I have a number of users and a number of pages, and each user can administrate any number of the pages, and each page can be administrated by any number of the administrators, how could I store all of these permissions in a database? For example, I could have a field in the users table, which is just a comma-delimited list of page ID...

C# Many-to-Many Class Modeling Problem

Please remember that I am not using any ORM tool. I have just written plain ado.net code for classes and methods look like exactly the following. And I am maintaining IDs also. Suppose I have three tables Teacher, Course and CourseTeacher(join table) for a Many-to-Many relationship and I have designed my classes accordingly. Now, suppo...

Fluent NHibernate auto mapping - how to create a many-to-many relationship table?

Hi, just wondered if anyone know if there is a way to crate a Many-to-Many relationship table automatically using some attribute? without creating the table, or mapping a class to become that relation table. If i add the attribute [ManyToMany(3,Class="DeploymentListUsers")] i get an error that this class isn't mapped to the DB. NH...

Is it possible to create a natural many to many relation in LinqToSql?

I have a content table and tags table I'd like to model a many to many relation between them. Can I hide the many to many table in Linq to SQL? So that my content will receive a field with a set of tags? Or should I switch to NHibernate? ...

Django ORM: Optimizing queries involving many-to-many relations

I have the following model structure: class Container(models.Model): pass class Generic(models.Model): name = models.CharacterField(unique=True) cont = models.ManyToManyField(Container, null=True) # It is possible to have a Generic object not associated with any container, # thats why null=True class Specific1(Gen...