NHibernate uni-directional associations -


Playing around with Whispered NHibernate's project I tried to customize some examples for some examples, for example, in them To eliminate circular references for JSON serialization.

The code I have entered should return the store and storemap class references to employee and products classes. It now looks like this:

Store / Storemap

  Public Square Shop {Public Virtual Ent ID (Receive; Private Set;} Public Virtual String {{get; set;}} Public StoreMap () {ID (x = & gt; x.Id); Map (x = & gt; x.Name);}   < P>  Employee / Employee Map   
  Public Class Employees {Public Virtual Ent ID (Receive; Private Set;} Public Virtual String First Name {Received; set;} Public Virtual String LastName {get} set {} public virtual store store {get} set;}} public class amplimmap: classplapp  gt; {public employee map () {id (x = & Gt; x.Id); Map (x => x.FirstName); Map (x => x.LastName); Reference (x => x.store) .Cascade.All () ;}}   

Product / Product map

  Public class product {public virtual ID (get; private set;} Public virtual st Ring name {get} Set; } Public virtual double value {get; Set; } Public Virtual Assistant & lt; Store & gt; Store stop in {get; Private set; } Public Products () {StoresStockedIn = New List & lt; Store & gt; (); } Public Virtual Zero Stock at (Store Store) {Store Stop In. Ad (Store); }} Public Category ProductMap: ClassMap & lt; Products & gt; {Public product map () {id (x => x.Id); Map (x = & x; x.Name); Map (x = & gt; x.price); HasManyToMany (x = & gt; x.StoresStockedIn) .Cascade.All () Table ("StoreProduct"); }}   

I have moved the "cascade" operation in product and employee instead of . From the tests I have done, both HasMany and HasManyToMany organizations are working fine.

My question is whether this is the right approach, whether or not it goes towards things that I have not anticipated.

As far as I know, it's standard practice in NHMNET for both of your relationship classes in a relationship Arrows (in fact, it is usually understood from a professional perspective) However, you do not do this (your example, I think, should work fine).
If you do not want to end one (or both), you can always define them privately or safely.

p.s Related JSON Serialization: It is not recommended to sort your model organizations. This is for some reasons, the top ones are: 1. 1. The data you show to the user may be different from your organizations (for example - you want to present an employee with their name, ID, The name of their store and the number of products they produce. It will be difficult to use your model sections.) 2. It is quite possible that you have an undetermined collection in your objects (if you are lazy-loading Use). Get it not serial tax

For the serialization, DTO is a recommended approach

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -