So, I want to define a Many-to-Many association, but I also want to store additional field in intermediate table. Is that possible? Something like this:
Updated at 15.03.2010 7:15:45Thanks for your answer, but I've found an issue on googlecode http://code.google.com/p/dataobjectsdot ... ail?id=595 and it says this is not working This thread was imported from our support forum. The original discussion may contain more detailed answer. |
Alex (Xtensive) wrote:Yes, this is possible. But inheriting from EntitySet<t> won't help here much - i.e. you can do this, but this won't help. Declare:
Actually I'm not sure if this will work - there might be issue, because the properties we pair to are inherited from base. If so, we'll fix this ASAP (as workaround, you can use AuthorBookLink w/o inheritance from Link<>). In any case, I hope this explains the idea itself: you must create an intermediate entity and pair 2 EntitySets to its "ends". Alex (Xtensive) wrote:The mistake shown in issue 595 was fixed before v4.2 release (as far as I can judge by provided exception message - we didn't try to clone the whole sample in our tests). But after today's review of our support forum I'm almost fully sure this won't work because of issue 619. We're working on bugfix. stefmen wrote:This is the linkclass that works:
This is the class that inherits:
psulek wrote:
stefmen wrote:The classes I posted are the implementation of how to achieve a many-to-many association with additional table fields (topic title.. :wink:) which Alex explained in pseudocode here:
jonepolvora wrote://I have the following scenario: //A table Company:
//A table Customer
//A table CompanyCustomer that do the association from both tables implemented using the hints of this topic:
the Link Class:
/* Everything is working like I was expecting.
*/
//I'd tried to insert a field at the Customer Class like this:
//But DataObjects created some other reduntant relationship tables that is not what I wish. //Any suggestions to get the Companies related to a given customer? otto wrote:CompanyCustomer in your model is an entity (not just a association), you should treat it that way. So your query: Customer cust=...; var custCompanies = (from cc in Query.All<companycustomer>() where cc.Customer==cust select cc.Company).ToList(); Alex (Xtensive) wrote:Yes, exactly. Since the association type you're going to use is custom one, you'll anyway see \ traverse it in queries. Few more advices: 1) Turn Link<tl, tr=""> into an abstract type, or, even better, get rid of it completely (i.e. use just CompanyCustomer). You need it just because of Left and Right properties, but there is no any generality except presence of these two properties here. On the other hand, this will make you using .Left and .Right instead of .Customer and .Company, which turns the code into much less readable. So it's nearly like using Tuple<tl,tr> as base class of any type having two fields. 2) Use pairing to its properties from Customer & Company to make this more usable:
In this case your query could be:
Issue 619 was fixed. v4.2.0 installers were updated to the latest stable revision. Hmm... And what's the issue? stefmen wrote: > Hmm... And what's the issue? No issue, just sharing! :P otto wrote: The query customer.Companies.ToList() would only work if there were a simple EntitySet-EntitySet paired assiciation with no intermediate link entity. |