My table was created with
CREATE TABLE orgs ( orgid int NOT NULL identity(1,1), orgname nvarchar (MAX) NOT NULL, PRIMARY KEY (orgid) );
and my C# class that mirrors it is
[Table(Name = "orgs")]
public class Organization
{
public Organization()
{
}
[Column(IsPrimaryKey=true)]
public int orgid { get; set; }
[Column]
public string orgname { get; set; }
}
However, when I issue the calls
PD.orgs.InsertOnSubmit(new Organization { orgname = newOrgName });
try
{
PD.SubmitChanges();
} // try submitting to db
catch (Exception e)
{
return Content(e.Message, "text/html");
}
I learn that
Cannot insert explicit value for identity column in table 'orgs' when IDENTITY_INSERT is set to OFF.
This confuses me because I thought it was equivalent to issuing the direct SQL command
INSERT INTO orgs (orgname) VALUES ('something');
and yet I don't get an error when I do that.
Any ideas how I can fix this?