LINQ to SQL Relationship Problem
hey, im using linq to sql, and in my database i have an events table, then i have a cakes table, every event uses ALL of the cakes in the cakes table. There is no explicit foreign key relationship, so how do i define an association between the two entities in the linq to sql classes? I simply need each event object to have references to ALL of the same cake objects.
Re: LINQ to SQL Relationship Problem
If you really have all cakes in each event and there is no relation between this two tables then there is also no sqlQuery to select specific cakes. Such tables are independent from each other. So simple load all cakes to a collection and refer to that collection in each event class. The linq command wold be similar to SQL Command 'Select * from cakes' without any 'Where' clause.
Re: LINQ to SQL Relationship Problem
Thanks for the reply! That's exactly what I want to do, the problem is the only way I know of to have the database automatically load a collection of objects from the database to one of my entity classes, is to use the association attribute and define an association. I don't have a reference to the data context from the event entity class, so I can't reference the cakes unless it's automatically loaded through an association. If I try to create a collection of cakes in each event, then each event will have a separate instance of the same cake, so if i edit the cake through one event, it won't be edited for all other events. I need to have a reference to the same cake objects in every event class. Please let me know if I'm missing something, cause this is what I understand at the moment. Thanks again!
Re: LINQ to SQL Relationship Problem
Simple create your event class and after that is loaded fire an event which causes the cakes to be loaded. If you are having one collection of cakes and no cpies of them then changing that cakes refered in one event class will change them in all events because you only deal with the address of the cakes colection. If you dont want that you need to create a copy of that cakes collection for each eventclass but this copy method could easily be part of your cakes collection class