Class NHRelationshipFixer
- Namespace
- Breeze.Persistence.NH
- Assembly
- Breeze.Persistence.NH.dll
Utility class for re-establishing the relationships between entities prior to saving them in Nhibernate.
Breeze requires many-to-one relationships to have properties both the related entity and its ID, and it
sends only the ID in the save bundle. To make it work with NH, we map the
many-to-one
entity, and map the foreign key ID with
insert="false" update="false"
, so the
many-to-one
entity must be populated in order for the foreign key value to be saved in the DB. To work around this problem, this class uses the IDs sent by Breeze to re-connect the related entities.
public class NHRelationshipFixer
- Inheritance
-
NHRelationshipFixer
- Inherited Members
Constructors
NHRelationshipFixer(Dictionary<Type, List<EntityInfo>>, IDictionary<string, string>, ISession)
Create new instance with the given saveMap and fkMap. Since the saveMap is unique per save, this instance will be useful for processing one entire save bundle only.
public NHRelationshipFixer(Dictionary<Type, List<EntityInfo>> saveMap, IDictionary<string, string> fkMap, ISession session)
Parameters
saveMapDictionary<Type, List<EntityInfo>>Map of entity types -> entity instances to save. This is provided by Breeze in the SaveChanges call.
fkMapIDictionary<string, string>Map of relationship name -> foreign key name. This is built in the NHBreezeMetadata class.
sessionISessionNHibernate session that will save the entities
Methods
FixupRelationships()
Connect the related entities in the saveMap to other entities. If the related entities are not in the saveMap, they are loaded from the session.
public List<EntityInfo> FixupRelationships()
Returns
- List<EntityInfo>
The list of entities in the order they should be save, according to their relationships.
RemoveRelationships()
Remove the navigations between entities in the saveMap. This flattens the JSON result so Breeze can handle it.
public void RemoveRelationships()