Questions tagged [datacontext]

A DataContext is used in WPF, Silverlight and various other .NET technologies. When used with WPF or Silverlight, a DataContext is an object holding the data that the form (or page in case of Silverlight) uses as a display source for its UI elements.

A DataContext is used in WPF, Silverlight and various other .NET technologies. When used with WPF or Silverlight, a DataContext is an object holding the data that the form (or page in case of Silverlight) uses as a display source for its UI elements. The DataContext in this case is the default object to bind against for any bindings that you have specified for other properties on the UI elements.

Ref: FrameworkElement.DataContext

1485 questions
9
votes
3 answers

Why isn't my transaction escalating to DTC?

DTC is disabled on my machine. It is my understanding that this code should fail, because it uses two data contexts in the same transaction. So, why does it work? (Note: I tried this using .NET 3.5 and .NET 4.0.) using (TransactionScope…
Bob Horn
  • 33,387
  • 34
  • 113
  • 219
9
votes
5 answers

How to detach a LINQ-to-SQL data object from the DataContext's tracking mechanism?

After asking this question, where I was informed of how the Table.Attach() method works, I have another question. How do you detach a LINQ-to-SQL data object from the DataContext's state tracking mechanism? Basically, I want to pull a record…
smartcaveman
  • 41,281
  • 29
  • 127
  • 212
9
votes
2 answers

Setting Datacontext on contentpresenter: Binding inside ContentTemplate is not working

I'm learning WPF and the MVVM Pattern and I'm trying to build a calendar-like view. So I currently have a Grid with 6 rows and 7 columns. The first row should be the Header, thus specifying the Week days like 'Monday, Tuesday, etc...' I have the…
Gilles Radrizzi
  • 999
  • 3
  • 10
  • 20
9
votes
4 answers

Default physical location of Data base created in Entity Framework codefirst approach

I am learning Entity Framework. I created a demo app using Entity framework code first approach (without specifying any connection string). static void Main(string[] args) { CreateBlog(); } private static void CreateBlog() …
Rasmita Dash
  • 917
  • 5
  • 15
  • 28
9
votes
3 answers

Can I set a DataContext to a static class?

I've a static class which reads information from the application assembly. I've declared it static since the class needs no instance declaration and will only ever be read directly from, application-wide. I have a control with several labels that I…
Will
  • 3,413
  • 7
  • 50
  • 107
9
votes
3 answers

Get object's DataContext

If I have the LINQ objects: public class SampleDataContext : DataContext { public Table Customers { get { return this.GetTable(); } } public SampleDataContext( string connectionString ) : base( connectionString ) {…
TcKs
  • 25,849
  • 11
  • 66
  • 104
9
votes
1 answer

How to asynchronously call a database with subrecords using LINQ?

I'm using EF6 and want to make the following query fully asynchronous: await MyDataContext.ADbSet. First(a => a.Something == "Something"). ASubCollection. Select(x => new {…
Alex
  • 75,813
  • 86
  • 255
  • 348
9
votes
4 answers

Entity Framework model change error

I am getting the error "The model backing the 'DataContext' context has changed since the database was created. Consider using Code First Migrations to update the database". I am using Entity Framework and have changed my model after declaring…
Amita Rai
  • 93
  • 1
  • 1
  • 3
9
votes
3 answers

How to bind column header to property in ViewModel? (WPF MVVM)

I Have window that have DataContext that is bind to ViewModel object (VM1 for the example). VM1 have a lot of properties and one of them is a string that called "MyTitle". I have a DataGridTextColumn in 'Window\Grid\DataGrid'. How can I bind the…
user436862
  • 867
  • 2
  • 15
  • 32
9
votes
2 answers

Can I access more than one table via the same DataContext object simultaneously?

Suppose I have a DataContext object and access two tables at the same time: using( var context = new DataContext( connectionString ) ) { foreach( firstTableEntry in context.GetTable() ) { switch( firstTableEntry.Type ) { …
sharptooth
  • 167,383
  • 100
  • 513
  • 979
8
votes
5 answers

LinqToSql static DataContext in a web application

In a web application that I have run across, I found the following code to deal with the DataContext when dealing with LinqToSQL public partial class DbDataContext { public static DbDataContext DB { get { if…
SBurris
  • 7,378
  • 5
  • 28
  • 36
8
votes
3 answers

MVVM Pattern, ViewModel DataContext question

I need to figure out how to communicate between ViewModels. I'm new to MVVM so please be kind. Here's a dumbed down example class definitions(assume that I have hooked the Child.PropertyChanged event in the ParentViewModel): public class…
Jose
  • 10,891
  • 19
  • 67
  • 89
8
votes
2 answers

How to cache DataContext instances in a consumer type application?

We have an application using SDK provided by our provider to integrate easily with them. This SDK connects to AMQP endpoint and simply distributes, caches and transforms messages to our consumers. Previously this integration was over HTTP with XML…
kuskmen
  • 3,648
  • 4
  • 27
  • 54
8
votes
2 answers

Should data contexts be static?

I am using entity framework 4 and I create an datacontext for model in one of the base classes. But I was in profiling it and the context is being created every time I try to query, So I thought of making it static so that it is created only once…
Vishal
  • 12,133
  • 17
  • 82
  • 128
8
votes
3 answers

WPF Update Binding when Bound directly to DataContext w/ Converter

Normally when you want a databound control to 'update,' you use the "PropertyChanged" event to signal to the interface that the data has changed behind the scenes. For instance, you could have a textblock that is bound to the datacontext with a…
Adam
  • 1,202
  • 11
  • 25