This question is locked. New answers and comments are not allowed.
Hi,
There are two tables: TableA (main) and TableB (additional). Each TableA record has zero or one linked records in TableB.
The TableA ORM object has tableB property:
public class TableA
{
....
public TableB tableB .....
}
and I have some troubles while dealing with this property.
1. I would like to be able to check whether tableB exists (is null) or not. I cannot just test:
if(tableAobject.tableB == null)
.......
because if tableB is missing I get an error message:
No row for ....TableB ....
I must check the existence of this object independently, asking the DB directly for this object.
2. Let's suppose I've read some TableA object - together with the existing TableB sub-object. After that and after doing some other work I decide that I must update some data in tableB. TableA object is read out of any transaction. If I try to do something like this:
someOtherScope.Transaction.Begin();
tableAobject.tableB.prop = newPropValue;
someOtherScope.Transaction.Commit();
I get an error in the second statement ("active transaction required for write operation"). I understand this - but it means that I must reread the whole TableA object (inside an active transaction). If I want to avoid reading it (this object may be pretty large) I must, again, read and then modify TableB object independently.
These two issues mean that there is nearly no advantage of making theses two classes related. What is the best practice in maintaining such relationship?
Best regard
Tomasz
There are two tables: TableA (main) and TableB (additional). Each TableA record has zero or one linked records in TableB.
The TableA ORM object has tableB property:
public class TableA
{
....
public TableB tableB .....
}
and I have some troubles while dealing with this property.
1. I would like to be able to check whether tableB exists (is null) or not. I cannot just test:
if(tableAobject.tableB == null)
.......
because if tableB is missing I get an error message:
No row for ....TableB ....
I must check the existence of this object independently, asking the DB directly for this object.
2. Let's suppose I've read some TableA object - together with the existing TableB sub-object. After that and after doing some other work I decide that I must update some data in tableB. TableA object is read out of any transaction. If I try to do something like this:
someOtherScope.Transaction.Begin();
tableAobject.tableB.prop = newPropValue;
someOtherScope.Transaction.Commit();
I get an error in the second statement ("active transaction required for write operation"). I understand this - but it means that I must reread the whole TableA object (inside an active transaction). If I want to avoid reading it (this object may be pretty large) I must, again, read and then modify TableB object independently.
These two issues mean that there is nearly no advantage of making theses two classes related. What is the best practice in maintaining such relationship?
Best regard
Tomasz