maxmahem
maxmahem
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
hah, well if you look at the code it already did some of thosoe.
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
anyways in SQL terms the DB would be something like:
CREATE TABLE People (
PersonId INT PRIMARY KEY AUTO_INCREMENT,
Name VARCHAR(100) NOT NULL,
Age INT
);

CREATE TABLE Friendships (
PersonId INT NOT NULL,
FriendId INT NOT NULL,
PRIMARY KEY (PersonId, FriendId),
FOREIGN KEY (PersonId) REFERENCES People(PersonId) ON DELETE CASCADE,
FOREIGN KEY (FriendId) REFERENCES People(PersonId) ON DELETE CASCADE,
CONSTRAINT CHK_NotSelfFriendship CHECK (PersonId != FriendId)
);
CREATE TABLE People (
PersonId INT PRIMARY KEY AUTO_INCREMENT,
Name VARCHAR(100) NOT NULL,
Age INT
);

CREATE TABLE Friendships (
PersonId INT NOT NULL,
FriendId INT NOT NULL,
PRIMARY KEY (PersonId, FriendId),
FOREIGN KEY (PersonId) REFERENCES People(PersonId) ON DELETE CASCADE,
FOREIGN KEY (FriendId) REFERENCES People(PersonId) ON DELETE CASCADE,
CONSTRAINT CHK_NotSelfFriendship CHECK (PersonId != FriendId)
);
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
good because I don't know as much about that side of things.
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
likewise, removing the id from the Person class, and using an auto-incrementing value instead.
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
I don't know how familiar you are with DBs, but the thing with using a hashset of Friendship objects makes more sense if you are used to lookup tables of that sort.
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
Sorry if I went to far here.
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
I find looking at solutions to problems to be inspirational. So I tend to give out a lot of implementations.
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
But what is important is that you understand it.
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
I mean I made it for you.
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
like each element that is yield returned because an element in the enumeration.
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
you could just build up a list and return that the normal way if you like instead
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
well... yield is kind of magic but basically it turns the method into a method that returns an IEnumerable
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
But yeah, that's a fancy way to get an IEnumerable out of a function.
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
happy to explain anything.
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
A unique set of values is a HashSet.
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
I used a HashSet because it best maps to the problem domain.
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
I'm out of control, I have to stop here: https://sharplab.io/#gist:34a5e789cfb6ab7f194111be4f42743d
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
might be better than to more closely mirror how it would be in a DB and have the Friends list be a hashset of (PersonId, PersonId)
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
hmm... and also remove the entry in every instance of the friends list. Cascading updates are a pita!
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
hmm... probably you should remove that entry from the friends list when you remove the person as well.
128 replies