2010-01-01 60 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