LinqToSql - “提交时插入”

发布于 2024-08-16 17:38:27 字数 888 浏览 4 评论 0原文

我正在尝试在我的一个表中插入一行, 所以我在网上查找使用 DATACONTEXT 的示例并找到了这个:

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 方法.. 有人知道为什么吗?

谢谢, 尤尼。

I'm trying to insert a row in to one of my tables,
so I look over the web to find an example for using the DATACONTEXT and found this one:

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();
  }
}

but when I try to use it and write : context.Guides. - now I can't see the InsertOnSubmit method..
does some one know why?

thanks,
yoni.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

呆° 2024-08-23 17:38:27

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

If you are using a LINQ-to-SQL Classes model (*.dbml), the Guides table must appear in the designer. Otherwise, the Guides class must descend from System.Data.Linq.Mapping.MetaTable.

总以为 2024-08-23 17:38:27

指南必须是不实现 InsertOnSubmit 方法的对象。

Guides must be an object that doesn't implement the InsertOnSubmit method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文