1
我无法弄清楚在子表中插入新记录的正确方法。不能插入新行到子表中提交更改在LINQ到SQL应用程序
应用程序中存在单个数据上下文,目标表(CustNotes)是名为Customer的表的子表。 Customer和CustNotes之间有一对多关联。 datacontext名称是CustomerOrdersDataContext。
下面是我使用的代码:
private void Button_Click(object sender, RoutedEventArgs e)
{
int newSeqNumber;
FindID = (int)lstCustomerNames.SelectedValue;
var CustNoteNum =
(from c in dbC.CustNotes
where c.CustomerID == FindID
select new
{c.NoteOrder}).Max(c => c.NoteOrder);
newSeqNumber = CustNoteNum + 1;
CustomerOrdersDataContext notes = new CustomerOrdersDataContext();
CustNote newNote = new CustNote();
newNote.Note = NewNote.Text;
newNote.NoteOrder = (byte)newSeqNumber;
newNote.CustomerID = FindID;
***notes.CustNotes.Add(newNote);***
notes.SubmitChanges();
}
错误涉及粗体,斜体线。那就是:
System.Data.Linq.Table”不包含定义‘添加’,没有扩展方法‘添加’接受一个类型的第一个参数‘System.Data.Linq.Table’可能被发现(你是否缺少使用指令或装配参考?)
任何人都会有帮助的线索。
了不起的帮助。谢谢。 这不仅工作,但它也指出了另一个bug ... newNote.Note = NewNote.Text; 应该是 newNote.Note = newNoteText.Text; – 2010-02-04 18:37:07