Saving objects with Cross-reference
-
larsp777 wrote:
Or could it be that the list I am trying to save is a empty list even if I use the same name?
Looks that way; a Kund holds a list of books. When you serialize the Kund, you write the PersonNr and the Name - but not the list. Again, I'd recommend not saving a list of books, but numbers that are linked to a book.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
Eddy Vluggen wrote:
Again, I'd recommend not saving a list of books, but numbers that are linked to a book.
Ok, Think I missunderstood you some. But I still have to save the objects somehow so I'm not really sure how that solves anything. Please explain. Edit: Realised that you probably ment the list saved in customer, not the list that holds all the books. That could be a way of avoiding cross-reference I guess.
-
Eddy Vluggen wrote:
Again, I'd recommend not saving a list of books, but numbers that are linked to a book.
Ok, Think I missunderstood you some. But I still have to save the objects somehow so I'm not really sure how that solves anything. Please explain. Edit: Realised that you probably ment the list saved in customer, not the list that holds all the books. That could be a way of avoiding cross-reference I guess.
larsp777 wrote:
But I still have to save the objects somehow so I'm not really sure how that solves anything. Please explain.
It'd be a translation from a database-design. Right now, each book would be stored in a Kund? That means that you'd be "moving" the book-data when the book moves between different Kunds; it'd be saved in a different list. If you had three lists, life could become easier; one list to hold a collection of Kunds, one to hold the Books, and one to hold a pointer to Kund/Book combinations. In SQL, it'd be something like below;
CREATE TABLE Customer
(
Id INT IDENTITY(1,1)
PRIMARY KEY (Id)
)CREATE TABLE Book
(
Id INT IDENTITY(1,1)
PRIMARY KEY (Id)
)CREATE TABLE LentItems
(
CustomerId INT,
BookId INT
FOREIGN KEY (CustomerId) REFERENCES Book(Id),
FOREIGN KEY (BookId) REFERENCES Book(Id)
)Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
larsp777 wrote:
But I still have to save the objects somehow so I'm not really sure how that solves anything. Please explain.
It'd be a translation from a database-design. Right now, each book would be stored in a Kund? That means that you'd be "moving" the book-data when the book moves between different Kunds; it'd be saved in a different list. If you had three lists, life could become easier; one list to hold a collection of Kunds, one to hold the Books, and one to hold a pointer to Kund/Book combinations. In SQL, it'd be something like below;
CREATE TABLE Customer
(
Id INT IDENTITY(1,1)
PRIMARY KEY (Id)
)CREATE TABLE Book
(
Id INT IDENTITY(1,1)
PRIMARY KEY (Id)
)CREATE TABLE LentItems
(
CustomerId INT,
BookId INT
FOREIGN KEY (CustomerId) REFERENCES Book(Id),
FOREIGN KEY (BookId) REFERENCES Book(Id)
)Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
Eddy Vluggen wrote:
Right now, each book would be stored in a Kund? That means that you'd be "moving" the book-data when the book moves between different Kunds; it'd be saved in a different list.
This is how it works (as far as I know): Every book is stored in a list BookList and every customer is saved in CustomerList; Every customer (Kund) has it´s own list loan where references are saved to books that are borrowed by that customer. Again, this was a project I made in Java for a University-course a while back. Been trying to transfer it to C#. Every book (Bok in Swedish) has a reference to the customer who borrowed the book, so it "knows" who borrowed it. The savingpart worked fine in Java but maybe works differently in C#.
-
Eddy Vluggen wrote:
Right now, each book would be stored in a Kund? That means that you'd be "moving" the book-data when the book moves between different Kunds; it'd be saved in a different list.
This is how it works (as far as I know): Every book is stored in a list BookList and every customer is saved in CustomerList; Every customer (Kund) has it´s own list loan where references are saved to books that are borrowed by that customer. Again, this was a project I made in Java for a University-course a while back. Been trying to transfer it to C#. Every book (Bok in Swedish) has a reference to the customer who borrowed the book, so it "knows" who borrowed it. The savingpart worked fine in Java but maybe works differently in C#.
larsp777 wrote:
Again, this was a project I made in Java for a University-course a while back. Been trying to transfer it to C#.
Every book (Bok in Swedish) has a reference to the customer who borrowed the book, so it "knows" who borrowed it. The savingpart worked fine in Java but maybe works differently in C#.Those references are pointers; I don't think that the XmlSerializer is going to save the private loan-list on it's own.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
larsp777 wrote:
Again, this was a project I made in Java for a University-course a while back. Been trying to transfer it to C#.
Every book (Bok in Swedish) has a reference to the customer who borrowed the book, so it "knows" who borrowed it. The savingpart worked fine in Java but maybe works differently in C#.Those references are pointers; I don't think that the XmlSerializer is going to save the private loan-list on it's own.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
Eddy Vluggen wrote:
Those references are pointers; I don't think that the XmlSerializer is going to save the private loan-list on it's own.
Yes, I know they are pointers. That is why you get cross-reference, isn´t it? Still, you could be right in that this is the problem. Edit: I think this was one thing I considered when I was trying to find the answer. Saving a list of books was no problem.
-
Eddy Vluggen wrote:
Those references are pointers; I don't think that the XmlSerializer is going to save the private loan-list on it's own.
Yes, I know they are pointers. That is why you get cross-reference, isn´t it? Still, you could be right in that this is the problem. Edit: I think this was one thing I considered when I was trying to find the answer. Saving a list of books was no problem.
-
-
larsp777 wrote:
No, I don't think I did it in XML. I saved the objects in a binary format.
:) If you save a collection using the binary-formatter, then it'll also save the pointers. If you use XML, you'll have to save the relations yourself, or keep a list.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
larsp777 wrote:
No, I don't think I did it in XML. I saved the objects in a binary format.
:) If you save a collection using the binary-formatter, then it'll also save the pointers. If you use XML, you'll have to save the relations yourself, or keep a list.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]