2010-01-01 61 views
1

我想在我的表之一插入一行, 所以我期待在网上找到使用DataContext的一个例子,这个发现之一:LinqToSql - “插上提交”

protected void buttonSave_Click(object sender, EventArgs e) 
{ 
    using (NorthwindDataContext context = new NorthwindDataContext()) 
    { 
    Customer customer = new Customer 
    { 
     CustomerID = textBoxCustomerID.Text, 
     CompanyName = textBoxCompanyName.Text, 
     ContactName = textBoxCustomerName.Text, 
     ContactTitle = textBoxTitle.Text, 
     Address = textBoxAddress.Text, 
     City = textBoxCity.Text, 
     Region = textBoxRegion.Text, 
     PostalCode = textBoxPostalCode.Text, 
     Country = textBoxCountry.Text, 
     Phone = textBoxPhone.Text, 
     Fax = textBoxFax.Text 
    }; 
    context.Customers.InsertOnSubmit(customer); 
    context.SubmitChanges(); 
    } 
} 

但是当我尝试使用它并写入:context.Guides. - 现在我看不到InsertOnSubmit方法.. 确实有人知道为什么吗?

谢谢, yoni。

+0

指南属性的类型是什么? – 2010-01-01 13:05:38

回答

0

指南必须是一个没有实现InsertOnSubmit方法的对象。

1

如果您使用的是LINQ-to-SQL类模型(* .dbml),则参考表必须出现在设计器中。否则,指南类必须从下降System.Data.Linq.Mapping.MetaTable