Help in using AttachObjectGraph
<p>I am using <code>AttachObjectGraph</code> and <code>SaveChanges</code> to save a record in my sql database. When I edit the object that I want to save, everything works fine. But when I create a new instance of the object and try to save it I get an <code>Object reference not set to an instance of an object.</code> exception on AttachObjectGraph. I am sure that I am giving values to all the properties of the object and not leaving anything blank or null. What is happening?  </p>

<p>Sample code:</p>

<pre><code>class SimpleOBJ
{
    public string userName;
    public string password;
}  

public void insertOBJ(SimpleOBJ S)
{
    if (string.IsNullOrEmpty(S.password))
        S.password = "test";
    db.AttachObjectGraph(S);
    db.SaveChanges();
}
</code></pre>
