Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
50
Binding Many to Many relationships in Ultragrid and displaying multiple values based on ID
posted

Hi, I'm not sure if my approach is correct but here is a sample scenario of what I'm trying to achieve.

Lets say I have two objects with a many to many relationship between them. For instance I can have a students collection, classes collection, and a collection of classes taken by students, ie studentsInClasses (this would be my many to many table with studentID and ClassID and thats it). Suppose I'm working on the student detail, I want to display a list of all classes that student is enrolled in. I'm using a binding source to bind a list of classes for that student. I'm using LINQ so the binding looks something like:

Var studentsInClasses = from s in StudentsInClasses where s.StudentId== CurrentStudent.Id select s;

bindingSource_StudentsClasses.datasource = studentsInClasses;

Ultragrid1_ClassesTakenByStudent.Datasource = bindingSource_StudentsClasses;

Now I want my ultragrid's datasource to be bindingSource_StudentsClasses, thats because as I add, delete classes from the grid, the grid notifies the binding source and the source updates my linq context and it properly deletes or adds the relationship. But I don't want to display classId, I want to display possible 3 or maybe 6 columns for the corresponding class values class name, start dates, etc, and I also want to display the headers somehow.

I know I can get this to work easy by just binding my grid to the actual classes just based on the classId but when the user presses the delete button the bindingSource is trying to tell the context to delete the actuall class, instead of removing the relationship between user and class, and I have to manually catch the delete event and go back and figure out which relationships to delete from the IDs.

I apologize if this is already answered in the forum, I looked for a while but I could not find a solution which worked for me.

 Thank you.

Chris D 

 

  • 2636
    posted

    I am a little confused on what you are trying to do other than delete/update some rows in a different table when a row is modifed/deleted etc.?

    I normaly do not let the interface dictate a chain of events like that but rather just create a trigger in the database to handle those kinds of things but if you can explain a little differently as I am a little out of it at the moment. :)