nHibernate <one-to-one> mapping - nhibernate

Please help me out
I am trying to do this but nHibernate not allowing can any one help me out how to do this?

Is it truly one-to-one in your data model is it one-to-one in your domain model?
I doubt you have two tables with same PK so you would not use one-to-one.
How to map it? HasOne x References

Related

What is the problem with many-to-many relationships?

I feel like I have searched through the internet to find an answer to this question for quite some time now, but without success. Does anyone feel comfortable explaining why many-to-many relationships should be replaced with a bridge table?
Probably most (all??) RDMS implement a M:N relationship by creating a table containing two columns with the FKs.
So there is no advantage to explicitely model the bridge table.
But in most realistic cases you want to store additional information (besides the fact of its existence) about the relationship instance, e.g. timestamp and user from the creation. That means that you need to model the bridge table anyway.

How can you map and work with a junction table in fluent nhibernate?

I have the classic scenario with 2 tables and a junction table.
Let's say, Locations, Prices and LocationXPrices.
LocationXPrices contains only the id's of Locations and Prices so that we know how they relate.
The best approach we came to is like this:
- map Locations as many to many to Prices
- map Prices as many to many to Locations
- no specific mapping and no .NET object for LocationsXPrices.
The junction will be created when Locations will be read.
Insert will be done together with Location.
Is this the best practice to work with this scenario ?
Can anyone provide a better solution ?
It doesn't' feel that natural to me.
Thank you,
Mosu.
Yes, this is best practice where your junction table represents a pure weak entity like this, with no other information. The junction table is merely a necessary artifact of modelling this sort of situation in an RDBMS; NHibernate lets you hide it totally so you can work with a genuine many-many relationship rather than the RDBMS's enforced many-one-many.

Question about E-R modelling

I've got the following business requirements for a scenario:
http://ompldr.org/vN2ZvdQ
and I came up with the following UML diagrams to model the relationship:
http://ompldr.org/vN2Y5Yg
I was wondering whether I have successfully managed to implement all the relations in the E-R model, especially the 1..* relationship. Furthermore, it is my understanding that mandatory relationships cannot be implemented just by using FK/PK so I have to add additional constraints, is that so?
Its seems to be ok. You can use ERWin or DBDesigner to doing your work in a easier way.
Consider ON DELETE CASCADE, ON UPDATE CASCADE, etc in your constraints.

NHibernate many-to-many inefficiency?

I'm trying to setup a sample project using NHibernate and Fluent NHibernate.
I am using the example mappings from the Fluent NHibernate web-site.
My question is about the many-to-many mapping between Store and Product. It seems (when looking at the generated SQL) that when adding a product to the store, NHibernate deletes all the records from the association table (StoreProduct) that belong to that store, and then inserts all the records again, now including the association to the new product I added.
Is this the default behavior or am I missing something? It just seems not very efficient to delete and re-insert all the associations every time I need to add one.
This is expected behavior. I believe this should only happen when you use the bag mapping strategy which it looks like they are using in the example. A bag indicates that there is an unordered collection that can have duplicate items. Because bag items are not unique NHibernate cannot tell when you've added or removed an item from a bag easily. The easiest thing for NHibernate then is to do is delete all associations and then re-add.
It's been a while since I've played with many-to-many mappings (I usually just map as two one-to-many relationships) but I believe that if you use use a different construct, for example, a set (which does not allow duplicates) you should find that the behavior is different. Of course, you should use what ever construct makes the most semantic sense for your application.

NHibernate ManyToMany relationship that includes all of one side of the relationship

Given this db schema (it was handed down to me):
(source: robtennyson.us)
I'd like suggestions on how to both model this and map it using fluent-nhibernate.
The only thing I can come up with is a very active record style of modeling (a class for each table and the obvious associations).
Ignoring the db for a second though, I think I want every facility to always have a list of all of the compliance flags. This way I can ask the facility what the compliance date for flag "XX" is.
Any help would be appreciated even it's only a slight nudge in the right direction.
Thanks,
Rob
I think the best way is what you've already suggested, to map each table as an entity. If you didn't have additional data in the join table you wouldn't need to, but as you do they should really be separate entities.
You'd have three entities. Facility and Compliance would have a HasMany to Facil_Compliance. You'd also have a References from Facil_Compliance back to each table. You may optionally remove a direction from this relationship if you only ever need to go one way.