0
Ado.net不在Windows手機中,因此在插入操作後如何獲得主鍵?如何在插入SQL Ce後獲得主鍵對於windows phone
在SQL方法:
SELECT @@IDENTITY
因此,對於SQL CE在Windows手機,如何使用LINQ做它的SQL或什麼的。
感謝
---更新時間:
這是你在列指的onInsert?
[Column(Storage="_CtcId", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
public int CtcId
{
get
{
return this._CtcId;
}
set
{
if ((this._CtcId != value))
{
this.OnCtcIdChanging(value);
this.SendPropertyChanging();
this._CtcId = value;
this.SendPropertyChanged("CtcId");
this.OnCtcIdChanged();
}
}
}
我得到了返回ID。請告知,如果這是獲得插入操作後,主鍵像這樣的正確的方法:當你插入一個對象
using (DBContacts context = new DBContacts(ConnectionString)) { //--- create object first: TblContacts tblCtc = new TblContacts(); tblCtc.FirstName = txtFirstName.Text.Trim(); tblCtc.LastName =txtLastName.Text.Trim(); tblCtc.Birthday = txtBirthday.Text.Trim(); tblCtc.NickName = txtNickName.Text.Trim(); context.TblContacts.InsertOnSubmit(tblCtc); context.SubmitChanges(); var id = tblCtc.CtcId; MessageBox.Show("Inserted Ok. Id is no :" + id.ToString()); }
如果它的工作原理,然後是它的正確途徑。 –