This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi guys, Is there any way to do a many to many relationship using NHibernate designer? I presume the answer is yes... (I hope...) Thanks, James |
|
|
I am also having a problem with one-to-one where the mapping is not being created properly meaning that the relationship is not being propogated to the database. |
|
|
OK... So the one-to-one was a problem on my side, I didn't realise how the one-to-one was implemented - i.e. same primary key on both entities so the db shows no link but NH knows which one to use. Still struggling with many-to-many relationships though in NHDesigner Thanks |
|
|
|
|
|
further to my previous, the one-to-one is not working either. The objects are being saved to the db, but the association is not there. |
|
|
Hello James, You can add a many-to-many or one-to-one association to the model, and it will be mapped in the class model, but we can't currently generate the underlying database table and foreign keys for it. Looking at the SO question, I'm not sure whether you're seeing a problem with the NHibernate mapping, or just with the database schema generation. If it's just the database schema generation, let us know and we'll see if we can add support for many-to-many and one-to-one associations in the next drop. (The reason they're not in there at the moment is just lack of time!) If there's a problem with the actual NHibernate mapping, again let us know and we'll investigate that as well. |
|
|
Hi James, Thinking about this, what kind of many-to-many collections would you need to generate database schemas for? Just bags, or would you need maps or lists as well? |
|
|
Hi Ivan, The problem is with the DB generation. What do I need to do to persist the many-to-many relationship? At the moment I am just using bags, though maps could also be useful for the project. With the one-to-one relationship, I can use 2 one-to-many relationships instead, so this isn't too much of a problem. |
|
|
If only this was shared source, I could implement the changes and push back to you... Alas! |
|
|
Thanks for the clarification. For the time being, you must create the join table manually. The table has the normal join table schema i.e. CREATE TABLE join_table_name ( where: join_table_name is the Table Name shown for the many-to-many arrow in NHibernate Designer and I've assumed both the 'main' tables have integer IDs. You'll also want to apply foreign key constraints to the key columns. I'll get this added to the designer, but for the time being creating a table like this in your database admin tool should be enough for you to continue your evaluation. |
|
|
Cool - thanks Ivan. |
|
|
Hello James, We have implemented support for creating many-to-many tables from the designer. If you downloaded the NHibernate Designer using VS2010 Extension Manager then just jump in there and check the Updates tab (it can be a bit slow to find things, so give it a few moments). If you downloaded it from Mindscape, then you'll have to wait for our nightly upload to run -- the new build should be up around 1200 GMT. It only supports bags at the moment, and doesn't support 'main' entities with composite keys -- only simple keys. We didn't implement composite keys because model-first developers are usually working in fairly modern databases, which generally follow NHibernate's advice and avoid natural keys for entities. But let us know if you need them. We also haven't done one-to-one associations yet because you said you were able to work around that with a pair of one-to-many associations. Please let us know if you run into any problems! |
|
|
Very impressed with the service! Thanks. I will download it now and have a play. Thanks :) Need any partners in Australia?? |
|
|
Many-to-Many is working great! One-to-One would be good when you can get to it as it's a good relationship to have in the toolset. Thanks again. |
|