So, first I would like to say that I use NHibernate for my project, and in this project we have (among other things) a synchronization function (for synchronization with the central MSSQL database with local SQLite), Now I know that NHibernate was not Created for database synchronization, but I would like to do it anyway.
I have an average database model, so I can’t add it here, but the problem is that I have two types of data and one reference table to link them.
Database Model:
| Product | | ProductLinkProducer | | Producer |
|--------------------| |---------------------| |---------------------|
| Id | | LinkId | | Id |
| Name | | Product | | Name |
| ProductLinkProducer| | Producer | | ProductLinkProducer |
Database:
| Product | | ProductLinkProducer | | Producer |
|---------| |---------------------| |----------|
| Id | | LinkId | | Id |
| Name | | ProductId | | Name |
| | | ProducerId | | |
Therefore, during synchronization, I first copy all the data from the Product table, and then from the Producer table (mostly var products = session.Query<Products>().ToList()). This is done by NHibernate in one statement each:
select
product0_.id as id2_,
product0_.name as name2_
from
Product product0_
(products.ForEach(x => session.Evict(x));)
(products.ForEach(x => syncSession.save(x));) - ( ).
, , , . . select ..., . , , .
, :
:
- insert (id 1)
- insert (id 2)
:
- insert (id 101)
- insert (id 102)
ProdLinkProducer:
- id 1
- id 1
- 101
- id 2
- id 2
- id 102
- id 102
?
, , . : https://github.com/tb2johm/NHibernateSync
( ghist, , , ...)
EDIT2
, .
, , , ProductLinkProducerSync, , , "sync". , , , , - , , .