corelibraries-devexpress-dot-data-dot-linq-fa913c16.md
The data source for the GridControl and SearchLookUpEdit that binds these controls to any queryable source (‘LINQ to SQL Classes’) in Instant Feedback Mode.
Namespace : DevExpress.Data.Linq
Assembly : DevExpress.Data.v25.2.dll
NuGet Package : DevExpress.Data
[ToolboxBitmap(typeof(ResFinder), "Bitmaps256.LinqInstantFeedbackSource.bmp")]
public class LinqInstantFeedbackSource :
Component,
IListSource,
IDXCloneable
<ToolboxBitmap(GetType(ResFinder), "Bitmaps256.LinqInstantFeedbackSource.bmp")>
Public Class LinqInstantFeedbackSource
Inherits Component
Implements IListSource,
IDXCloneable
Instant Feedback binding mode is an improvement over regular server mode. In server mode, the Grid Control loads data in small portions and delegates all data operations (sorting, grouping, filtering and calculating summaries) to the data server. This is the key to the server mode’s high efficiency when working with large volumes of data. The only drawback to using server mode involves data operations when the connection to the server is slow. In this instance, the bound control freezes until the data server completes operations and retrieves results. With Instant Feedback binding mode, data operations are performed asynchronously in a background thread, and both the bound control and the application remain highly responsive. Currently, this mode is supported by the GridControl and SearchLookUpEdit controls.
For additional information on Instant Feedback mode, refer to the Large Data Sources: Server and Instant Feedback Modes section.
Note
The LinqInstantFeedbackSource is a read-only data source.
This example demonstrates how to initialize a LinqInstantFeedbackSource, to retrieve data from a “Purchasing.PurchaseOrderHeader” data table (included in the AdventureWorks database shipped with MS SQL Server). The PurchaseOrderHeader persistent class is declared, and mapped to the “Purchasing.PurchaseOrderHeader” data table using the System.Data.Linq.Mapping.TableAttribute attribute. Then, a System.Data.Linq.Table<PurchaseOrderHeader> is passed to the LinqInstantFeedbackSource in the LinqInstantFeedbackSource.GetQueryable event handler.
using System.ComponentModel;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using DevExpress.Data.Linq;
// The class describing the "Purchasing.PurchaseOrderHeader" table
// from the AdventureWorks SQL database
[Table(Name="Purchasing.PurchaseOrderHeader")]
public partial class PurchaseOrderHeader : INotifyPropertyChanging, INotifyPropertyChanged {
//...
[Column(Storage="_PurchaseOrderID", AutoSync=AutoSync.OnInsert,
DbType="Int NOT NULL IDENTITY",
IsPrimaryKey=true, IsDbGenerated=true)]
// The property mapped to the primary key column
public int PurchaseOrderID {
//...
}
//...
}
// The class describing the AdventureWorks SQL database
[DatabaseAttribute(Name="AdventureWorks")]
public partial class AdvWorksDataContext : DataContext {
//...
public System.Data.Linq.Table<PurchaseOrderHeader> PurchaseOrderHeaders {
get {
return this.GetTable<PurchaseOrderHeader>();
}
}
//...
}
public partial class Form1 : Form {
//...
private void Form1_Load(object sender, EventArgs e) {
// Specify the key property of the PurchaseOrderHeader
linqInstantFeedbackSource1.KeyExpression = "PurchaseOrderID";
// Handle the GetQueryable event, to create a DataContext and assign a queryable source
linqInstantFeedbackSource1.GetQueryable += linqInstantFeedbackSource1_GetQueryable;
// Handle the DismissQueryable event, to dispose of the DataContext
linqInstantFeedbackSource1.DismissQueryable += linqInstantFeedbackSource1_DismissQueryable;
// Assign the created data source to an XtraGrid
gridControl1.DataSource = linqInstantFeedbackSource1;
}
void linqInstantFeedbackSource1_GetQueryable(object sender, GetQueryableEventArgs e) {
// Instantiate a new DataContext
AdvWorksDataContext dataContext = new AdvWorksDataContext();
// Assign a queryable source to the LinqInstantFeedbackSource
e.QueryableSource = dataContext.PurchaseOrderHeaders;
// Assign the DataContext to the Tag property,
// to dispose of it in the DismissQueryable event handler
e.Tag = dataContext;
}
void linqInstantFeedbackSource1_DismissQueryable(object sender, GetQueryableEventArgs e) {
// Dispose of the DataContext
((AdvWorksDataContext)e.Tag).Dispose();
}
}
Imports System.ComponentModel
Imports System.Data.Linq
Imports System.Data.Linq.Mapping
Imports DevExpress.Data.Linq
' The class describing the "Purchasing.PurchaseOrderHeader" table
' from the AdventureWorks SQL database
<Table(Name:="Purchasing.PurchaseOrderHeader")> _
Partial Public Class PurchaseOrderHeader
Implements INotifyPropertyChanging, INotifyPropertyChanged
'...
' The property mapped to the primary key column
<Column(Storage:="_PurchaseOrderID", AutoSync:=AutoSync.OnInsert, _
DbType:="Int NOT NULL IDENTITY", _
IsPrimaryKey:=True, IsDbGenerated:=True)> _
Public ReadOnly Property PurchaseOrderID() As Integer
'...
End Property
'...
End Class
' The class describing the AdventureWorks SQL database
<DatabaseAttribute(Name:="AdventureWorks")> _
Partial Public Class AdvWorksDataContext
Inherits DataContext
'...
Public ReadOnly Property PurchaseOrderHeaders() As Table(Of PurchaseOrderHeader)
Get
Return Me.GetTable(Of PurchaseOrderHeader)()
End Get
End Property
'...
End Class
Partial Public Class Form1
Inherits Form
'...
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
' Specify the key property of the PurchaseOrderHeader
linqInstantFeedbackSource1.KeyExpression = "PurchaseOrderID"
' Handle the GetQueryable event, to create a DataContext and assign a queryable source
AddHandler linqInstantFeedbackSource1.GetQueryable, _
AddressOf linqInstantFeedbackSource1_GetQueryable
' Handle the DismissQueryable event, to dispose of the DataContext
AddHandler linqInstantFeedbackSource1.DismissQueryable, _
AddressOf linqInstantFeedbackSource1_DismissQueryable
' Assign the created data source to an XtraGrid
gridControl1.DataSource = linqInstantFeedbackSource1
End Sub
Private Sub linqInstantFeedbackSource1_GetQueryable(ByVal sender As Object, _
ByVal e As GetQueryableEventArgs)
' Instantiate a new DataContext
Dim dataContext As New AdvWorksDataContext()
' Assign a queryable source to the LinqInstantFeedbackSource
e.QueryableSource = dataContext.PurchaseOrderHeaders
' Assign the DataContext to the Tag property, _
' to dispose of it in the DismissQueryable event handler
e.Tag = dataContext
End Sub
Private Sub linqInstantFeedbackSource1_DismissQueryable(ByVal sender As Object, _
ByVal e As GetQueryableEventArgs)
' Dispose of the DataContext
CType(e.Tag, AdvWorksDataContext).Dispose()
End Sub
End Class
Object MarshalByRefObject Component LinqInstantFeedbackSource
See Also