[Column(Name = "id", IsPrimaryKey = true, CanBeNull = false)]
public string id { get; set; }
Error:
Cannot insert the value Null into column id, column does not allow nulls
If I set it to an identity column and make a few changes in my [Column attributes]
I end up with a IDENTITY insert not enabled error, what should I do? Do I need my primary key column to be an identity as well?
It's just a simple table with +1 increment on primary key
public partial class linqtest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
MyContext db = new MyContext("Server=(local);Database=Test;User ID=admin;Password=pw");
Child c = new Child();
c.name = "joe "+DateTime.Now;
db.parents.InsertOnSubmit(c);
db.SubmitChanges();
}
}
public class MyContext : DataContext
{
public static DataContext db;
public MyContext(string connection) : base(connection) { }
public Table<Parent> parents;
}
[Table(Name="parents")]
[InheritanceMapping(Code = "retarded", Type = typeof(Child), IsDefault=true)]
public class Parent
{
[Column(Name = "id", IsPrimaryKey = true, CanBeNull = false, DbType = "Int NOT NULL IDENTITY", IsDbGenerated = true)] /* I want this to be inherited by subclasses */
public int id { get; set; }
[Column(Name = "name", IsDiscriminator = true)] /* I want this to be inherited by subclasses */
public string name { get; set; }
}
public class Child : Parent
{
}