我有一个DataContext
:LINQ,转换表列出并插入新记录
public class DatabaseCatalogue : DataContext
{
// other stuffs ...
public Table<IngramProduct> IngramProducts;
}
我的IngramProducts
表加载到一个列表:
private List<IngramProduct> ingramProducts =
(from ingramProduct in dbCatalogue.IngramProducts
select ingramProduct).ToList();
如果我改变的一个值这个列表中的一个对象的属性,然后调用dbCatalogue.SubmitChanges();
,它被保存到数据库中。
但是,如果我创建一个新对象并将此对象插入列表中,它将不会保存为表中的新记录(当调用SubmitChanges
时)。
我的问题是:如何将新对象添加到列表中并将其保存为数据库中的新记录(调用SubmitChanges
方法)?
_“如果我创建一个新对象并将该对象插入到列表中,它不会被保存为表中的新记录”_ ...是否将它添加到'Table'中,或者只是添加到“Table”中'List'?因为如果只将它添加到'List'中,那么'Table'如何知道它有一个新的行要保存? –