datacontext

WPF Simple Binding to INotifyPropertyChanged Object

孤街醉人 提交于 2019-12-10 13:29:42
问题 I've created the simplest binding. A textbox bound to an object in the code behind. Event though - the textbox remains empty. The window's DataContext is set, and the binding path is present. Can you say what's wrong? XAML <Window x:Class="Anecdotes.SimpleBinding" x:Name="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="SimpleBinding" Height="300" Width="300" DataContext="MainWindow"> <Grid> <TextBox

Entity framework: life of datacontext?

荒凉一梦 提交于 2019-12-10 11:51:32
问题 I am reading about which is the recommended life for the data context, but I still have some doubts about the best option. In general, the conclusion that I see is that in desktop applications the life of the data context should be the life of the form, and in WCF applications the life should be the life of the session. The reason, if I understand, it's that the life of the data context should be enough large to have the advantages of the unit of work of the context but no very large to lost

Multi-threading with Linq to SQL

隐身守侯 提交于 2019-12-10 08:16:33
问题 I am building an application which requires me to make use of DataContext's inside threads. My application keeps throwing InvalidOperationException 's similar to: There is already an open DataReader associated with this Command which must be closed first ExecuteReader requires an open and available Connection. The connection's current state is connecting These exceptions are intermittant. Here is a snippet of my code: var repo = new Repository(); var entities = repo.GetAllEntities(); foreach

Entity Framework model change error

你离开我真会死。 提交于 2019-12-10 02:50:24
问题 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 DataContext . How can I fix this error? 回答1: If you already deployed your application or you don't want remove data from database you must read about Code First Migrations. Here you have a link: http://msdn.microsoft.com/en-us/library/hh770484(v=vs.103)

Where should I set the DataContext - code behind or xaml?

巧了我就是萌 提交于 2019-12-10 01:52:03
问题 (honestly I searched and read all the 'related questions' that seemed relevant - i do hope i didn't "miss" this question from elsewhere but here goes...) There are two different ways (at least) to set the DataContext. One can use XAML or one can use the code behind. What is the 'best practice' and why? I tend to favor setting it in XAML because it allows a designer to define collections on their own but I need 'ammunition' on why it's a best practice or why I'm crazy and the code behind is

Wpf datacontext binding using MVVM between viewmodel and view

徘徊边缘 提交于 2019-12-09 16:31:57
问题 I just started learning MVVM and here is what seems to be basic question but I spent whole day trying to figure it out. I have a solution that contains 3 projects one for Model, one for ViewModel and one for View. The Model contains a class that has 2 properties Text and CheckStatus. The ViewModel has a list called listOfItems that has three items, each item has these 2 properties from the Model. The View has a listView inside it there is a CheckBox. What is the proper way to bind the

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

隐身守侯 提交于 2019-12-09 15:50:12
问题 After asking this question, where I was informed of how the Table<T>.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 and change the data on the record. But, when I call SubmitChanges() on the same DataContext instance, I do not want the record to be updated unless I have explicitly called Attach() . How is this accomplished? 回答1: From this site explaining how to

Misunderstanding databinding fundamentals and DataContexts — long story

℡╲_俬逩灬. 提交于 2019-12-09 13:51:08
问题 I've been using databinding in several simple situations with pretty good success. Usually I just use INotifyPropertyChanged to enable my codebehind to modify the GUI values on screen, rather than implement dependency properties for everything. I am playing with an LED control to learn more about databinding in user controls, and was forced to use dependency properties because VS2008 told me I had to. My application is straightforward -- I have a window that displays several LED controls,

Which layer should create DataContext?

て烟熏妆下的殇ゞ 提交于 2019-12-09 05:54:25
I have a problem to decide which layer in my system should create DataContext. I have read a book, saying that if do not pass the same DataContext object for all the database updates, it will sometimes get an exception thrown from the DataContext. That's why i initially create new instance of DataContext in business layer, and pass it into data access layer. So that the same datacontext is used for all the updates. But this lead to one design problem, if i wanna change my DAL to Non-LinqToSQL in future, i need to re-write the code in business layer as well. Please give me some advice on this.

Can I set a DataContext to a static class?

浪子不回头ぞ 提交于 2019-12-09 00:34:22
问题 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 would like to use to display some of this information. How can I go about setting the controls DataContext equal to the class? Code: /// <summary> /// Class for Reading Program Information. /// </summary> public static class ProgramInfo { private