I hope I am not missing something obvious here. When trying to make modifications to a database using linq, you must have a primary key. My database has a primary key and I have identified it in the class.
Code:
[Table(Name = "Accounts")]
public class AllAccounts
{
[Column(DbType = "int not null, IsPrimaryKey=true, IsDBGenerated=true")]
public int AccountID;
However when I atempt to insert data, I get the following error.
"Can't perform Create, Update or Delete operations on 'Table(AllAccounts)' because it has no primary key."
Code:
public class DRCACCT : DataContext
{
public DRCACCT(string connection) : base(connection) { }
//table definitions
public Table<VItems> Items;
public Table<AllAccounts> AllAccount;//Account
}
Code:
DRCData.AllAccounts pacct = new DRCData.AllAccounts();
pacct.IsValid = true;
pacct.ApplicationOwner = "DRCTECH";
pacct.AccountType = 6;
pacct.Name = User.Identity.Name + DateTime.Now.ToString();//tbDescription.Text;
pacct.Active = true;
pacct.CreatedBy = User.Identity.Name;
pacct.CreatedDateTime = DateTime.Now.ToShortDateString();
pacct.OpeningBalanceDate = DateTime.Now.ToShortDateString();
pacct.OpeningBalance = 0;
db.AllAccount.InsertOnSubmit(pacct);
db.SubmitChanges();
I thought this was working at one point, but in trying to solve another problem, I removed it and then put it back. I point this out because I am using VS2008 and have noticed that sometimes changes I have made to my code does not get updated somewhere in the vsguts. So perhaps, somewhere in the depths of VS this code is not what it appears to be. Or perhaps there is just something wrong with the code itself and I have overlooked it. Any help would be appreciated.