[C#学习] GridControl Binding to LINQ to SQL Classes

Binding to LINQ to SQL Classes

Binding to LINQ to SQL Classes

 

  1. Open the Visual Studio Server Browser and right-click "Data Connections" to add a new connection.

  2. Invoke a Data Source Configuration Wizard and select the "LINQ to SQL" option.

  3. Click "New Data Source..." button and add a new "LINQ to SQL Classes" item to your project.

    If LINQ to SQL tools are not installed, this button is hidden. To do so, install these tools manually as shown in the Prerequisites section.

  4. Data classes are created and edited in an Object Relational Designer (O/R Designer). To create a data class, drag it from the Server Explorer onto the O/R Designer's surface.

  5. Rebuild the project and close the O/R Designer.

  6. Invoke a Data Source Configuration Wizard once again and select the "LINQ to SQL" option. This time the data source you have created is listed among available data sources. Select it and click "Next".

  7. Choose the required data binding mode.

    • Direct Binding to Data Source - the data-aware control binds directly to the data source, without any go-between components.
    • Binding via the BindingSource Component - a new System.Windows.Forms.BindingSource component is created to transfer data to your data-aware control.
    • Asynchronous Server-Side Data Processing - the LinqInstantFeedbackSource component transfers data. The data-aware control operates in Instant Feedback Mode.
    • Server-Side Data Processing - the LinqServerModeSource component transfers data. The data-aware control operates in Server Mode.
    • Asynchronous Parallel In-Memory Data Processing - the PLinqInstantFeedbackSource component transfers data. The data-aware control operates in Instant Feedback Mode.
    • Parallel In-Memory Data Processing - the PLinqServerModeSource component transfers data. The data-aware control operates in Server Mode.
  8. The final wizard page allows you to sort your data descending or ascending by a selected data field.

  9. Click "Finish" and rebuild the solution. Your data-aware control is now bound to LINQ-to-SQL classes.

Expanded Posting Data Back to the Data Source

Call the SubmitChanges method to save changes back to a data-aware control's underlying data source.

C#
VB
 
//direct binding 
private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
    (gridControl1.DataSource as Table<Order>).Context.SubmitChanges();
}

//binding with a BindingSource component  private void Form1_FormClosing(object sender, FormClosingEventArgs e) { (ordersBindingSource.DataSource as Table<Order>).Context.SubmitChanges(); } 

转载于:https://www.cnblogs.com/AngryZe/p/7249388.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值