I am using the Sqlite-Net PCL, together with SQLite-Net for the development of an application using Examiner Extension.
I have one of several relationships between two classes a
and B
, as defined:
Public category A {[PrimaryKey, Auto Incorrect] Public Int ID (Received); Set; } Public string name {get; Set; } [Van Tommy (Cascade Operation = Cascade Operation. All)] Public List & lt; B & gt; Bates {receives; Set; } Public A () {} Public A (string name, list & lt; B & gt; sons) {name = name; Sans = son; }} Public Class B [[Primary, Auto Inquiry] Public Entity ID (Received); Set; } Public string name {get; Set; } [Foreign (Typef (A))] Public Int Foundation (Received; Set; } [ManyToOne] Public One Father (Mill); Set; } Public B () {} Public B (name of string) {name = name; }}
What I would like to do is obtain an object from the database in A
, Sons
objects type B
and update the database accordingly. This is what I've tried:
var sons = new list & lt; B & gt; {New B ("Ano"), New B ("Reason"), New B ("Tray"),}; A = new A ("Pedre", son); (Con con.DeleteAll & lt; A & gt; (); conn.DeleteAll & lt; p & gt; (); Conn.InsertWithChildren (one, true); using (var conn = DatabaseStore.GetConnection ()); Retrieve a recovered = conn.GetWithChildren & lt; a & gt; (one.Id); retrieved.Sons.RemoveAt (1);} (var conn = DatabaseStore.GetConnection ()) using {var retrieval = conn.getWithChildren & Lt; a & gt; (one.Id); retrieved.Sons.RemoveAt (1); // "Reason" //conn.updateWithChildren (Recover); Conn.InsertOrReplaceWithChildren (Recover, True);}
< / Pre>The problem is that the object with both the
UpdateWithChildren
andInsertOrReplaceWithChildren
is not actually removed from the database, Is it possible to delete thisson
object, only this foreign key drain?
You are not really trying to delete any object. You are just removing the relationship between two objects, but nothing more than anything about them stops you from anything, so any It is not right to remove it because you can break other relationships.
It should be more like:
using (var conn = DatabaseStore.GetConnection ()) {var retrieved = conn.GetWithChildren & lt; A & gt; (One.Id); Reason for Var = Recovery Source [1]; // It is not necessary if the foreign key is on the other end, // but it would be the normal way to recover any other scenario // Source. Remove (Reason); // conn.UpdateWithChildren (recover); // If the database does not need to be present in the conn.delete (cause), then delete the object; }
No comments:
Post a Comment