Linq Tutorials: Data context

search facility - linq



Its a class.DataContext performs 3 tasks:
Connect to a database
Access data
Submit changes back to the server

The DataContext is generated by the Object Relational Designer.Entity classes such as Aanmelder are usually accessed via the DataContext. In our sample program the DataContext is also stored in AGVd0001Entities.designer.cs. The declaration for the DataContext looks like this:

[System.Data.Linq.Mapping.DatabaseAttribute(Name = "DataBaseName")]
public partial class AGVd0001EntitiesDataContext : System.Data.Linq.DataContext
{
… Code omitted here
}

The DatabaseAttribute shown in the above code fragment tells the compiler to link the DataContext to the database on the server.

Inside AGVd0001EntitiesDataContext is property called Aanmelders:

public System.Data.Linq.Table Aanmelders
{
get
{
return this.GetTable();
}
}

If you write a LINQ query that retrieves records from the database, then you can access that data via this property. It is of type Table, where the internal Table class becomes in this case a collection of Aanmelder records.
When a query is executed, instances of the Aanmelder class are automatically instantiated and filled with data from the database. The variable db.Aanmelders references the collection of Aanmelder records stored in the DataContext.

For more information Click here

Comments