ASP.NET Loading Data into Table with Navigation Property
<p>I have a created Entity Framework.I am trying to add a new songs and New album to the table. For example when I try to add a new song I used the method below and it tells me "Object reference not set to an instance of an object" on the s.Artist.ArtistName. I have a webform that shows a list of Artists in a drop down menu and now I want to add a new song for that artist. How do I do that?</p>

<pre><code>public Song AddNewSongNav(String ArtistName, String SongName)
{
    using (var context = new MyEntities())
    {
        var s = new Song();
        s.SongTitle = SongName;
        s.Artist.ArtistName = ArtistName;
        s.Artist.WikipediaUrl="http://en.wikipedia.org/Testing";

        context.Songs.AddObject(s);
        context.SaveChanges();
        return s;
    }
}
</code></pre>

<p>The frame work for the Artist Table has ArtistID,ArtistName and WikiPediaURL. It has a navivgation property for Album and Song. It is linked to Song as 1 to many and Album as 1 to Many.</p>

<p>It has a Song table, which has a SongID, SongTitle and Artist_ArtistID. It has a navigation property of Artist and Album. It's linked as a many to many to the Albums table.</p>

<p>Finally the Album table has an AlbumID,AlbumTitle,CoverArt,Year,Genre,MimeType and Artist_ArtistID. It has a navigation property of Artist and Song. </p>
