I have another weird one here... MVC3 and Entity Framework database first...
I am making an app that's going to allow adding items from one list to another list (songs onto set lists to be exact)
in the "edit" view is where I have "add to set list" links that link to a actionmethod that enters the row into the "SetListSongs" table - so far so good - the row gets added and everything works fine
but when I return to the Edit View - the loop that lists the songs that are on the list is throwing an error - it "sees" that there is a new song (it's a foreach loop) but when it's trying to add the title from the song that was added it says "Object reference
not set to an instance of an object."
I do not understand why a song ( maybe a songviewmodel?!)have a song. Anyway, you can look in the database to see if there is a link with songid or prevent
Thanks for the help - the model is actually a "Set List" and a Set List can have any number of Songs - so my loop is runnig through all of the songs on the set list and listing their titles
the row is added to the database just fine - and if I go to the index view first and then back to the edit view everything works - but I don't want to have to go back to the index every time I add a song to a set list
is there something that can be called to "refresh" the database in the app?
after the savechanges and before the reloading of the SetLsit and it's still the exact same error
here's a question - when i am passing the Setlist back to the view - it's a brand new view right? I mean there's no way that the previous view is still there and holding onto the old setlist model - right?
GeeksGoneBad
Member
129 Points
57 Posts
Problem after adding row - not refreshing?
Feb 17, 2012 06:22 PM|LINK
I have another weird one here... MVC3 and Entity Framework database first...
I am making an app that's going to allow adding items from one list to another list (songs onto set lists to be exact)
in the "edit" view is where I have "add to set list" links that link to a actionmethod that enters the row into the "SetListSongs" table - so far so good - the row gets added and everything works fine
but when I return to the Edit View - the loop that lists the songs that are on the list is throwing an error - it "sees" that there is a new song (it's a foreach loop) but when it's trying to add the title from the song that was added it says "Object reference not set to an instance of an object."
here's my controller action:
ignatandrei
All-Star
135142 Points
21676 Posts
Moderator
MVP
Re: Problem after adding row - not refreshing?
Feb 18, 2012 01:24 AM|LINK
Which line? this one?
GeeksGoneBad
Member
129 Points
57 Posts
Re: Problem after adding row - not refreshing?
Feb 18, 2012 11:52 AM|LINK
no the error is in the view on the line
@song.Song.Titlebut it goes through 3 iterations (or how many songs there were before the add)
just fine and errors on the third (the one that was added)
it's almost like the database was updated with the number of rows that shouldbe there but not with the data that was addded or something
ignatandrei
All-Star
135142 Points
21676 Posts
Moderator
MVP
Re: Problem after adding row - not refreshing?
Feb 18, 2012 06:01 PM|LINK
I do not understand why a song ( maybe a songviewmodel?!)have a song. Anyway, you can look in the database to see if there is a link with songid or prevent
@if(song.Song == null)...GeeksGoneBad
Member
129 Points
57 Posts
Re: Problem after adding row - not refreshing?
Feb 18, 2012 06:22 PM|LINK
Thanks for the help - the model is actually a "Set List" and a Set List can have any number of Songs - so my loop is runnig through all of the songs on the set list and listing their titles
the row is added to the database just fine - and if I go to the index view first and then back to the edit view everything works - but I don't want to have to go back to the index every time I add a song to a set list
is there something that can be called to "refresh" the database in the app?
GeeksGoneBad
Member
129 Points
57 Posts
Re: Problem after adding row - not refreshing?
Feb 20, 2012 04:51 PM|LINK
I have verified that the row is entered into the database on the "SaveChanges" call
and after the call I have verified that there's another row in the SetListSongs as you'd expect - but the data itself is not there!
is there anyway to refresh the data in memory? I tried "Refresh" but it dosn't seem to exist in EF4? How do I refresh ?
ignatandrei
All-Star
135142 Points
21676 Posts
Moderator
MVP
Re: Problem after adding row - not refreshing?
Feb 20, 2012 08:03 PM|LINK
reload from database.
GeeksGoneBad
Member
129 Points
57 Posts
Re: Problem after adding row - not refreshing?
Feb 20, 2012 08:17 PM|LINK
I am already doing
and passing the setlist back to the view - is there another way to reload from the database?
ignatandrei
All-Star
135142 Points
21676 Posts
Moderator
MVP
Re: Problem after adding row - not refreshing?
Feb 20, 2012 08:33 PM|LINK
close the db and re-open.
GeeksGoneBad
Member
129 Points
57 Posts
Re: Problem after adding row - not refreshing?
Feb 20, 2012 08:49 PM|LINK
No dice - I tried adding
after the savechanges and before the reloading of the SetLsit and it's still the exact same error
here's a question - when i am passing the Setlist back to the view - it's a brand new view right? I mean there's no way that the previous view is still there and holding onto the old setlist model - right?