geekpgh / mastersproject

The masters project for SWENG 500 team 3
4 stars 2 forks source link

Friends not working #77

Closed steveplatz closed 11 years ago

steveplatz commented 11 years ago

When I try to enumerate the friends collection for a user object, I get null reference exceptions. I also assume that friends is a many to many relationship, but don't see the join table that would be necessary to pull this off in the database. Is this something that still needs to be worked on?

geekpgh commented 11 years ago

@steveplatz I think I just fixed this 30 seconds ago. The entity framework was initializing all our collections to null. I made them initialize to an empty list with a constructor. Try this in 5 minutes when Azure syncs up.

gmblogref commented 11 years ago

I don't know why this is not working for you. I think this is a one to many relationship. I can add friend and show them on the friends page in a list.

steveplatz commented 11 years ago

I'm surprised that this would be a one to many relationship. Wouldn't the friendship go both ways, such that I can have many friends and they can also have many friends?

gmblogref commented 11 years ago

I guess I am looking at it different. I see it as me (one) has many friends. Every one person has many friends, I don't see it as many of me has many friends.

gmblogref commented 11 years ago

Yes the friendship goes both ways since the person being friended has to accept.

steveplatz commented 11 years ago

You're right with that, but if you look at the way the model is currently set up, the friendship is defined by the UserProfile_UserId column. So, if I were to add you as a friend, the database would look like this:

| UserId | UserName | UserProfile_UserId |
|--------|----------|--------------------|
| 1      | steve    | null               |
| 2      | geoff    | 1                  |
| 3      | jon      | null               |
|--------|----------|--------------------|

But how could you ever be linked as Jon's friend?

steveplatz commented 11 years ago

@geekpgh I also forgot to reply to you, but yes, the changes you made did fix the initial issue I was running into.

gmblogref commented 11 years ago

I took from an example online. I thought that the joined table would be hidden like for IngredientRecipe. Maybe I need to add this: modelBuilder.Entity() .HasMany(c => c.Recipes) .WithMany(i => i.Ingredients) .Map(t => t.MapLeftKey("IngredientID") .MapRightKey("RecipeID") .ToTable("IngredientRecipe"));

for UserProfile. Because I just tried to add 3 friends to each other and it messed things up.

gmblogref commented 11 years ago

Got this to work as a one to many relationship