datacontext

How do I correctly manage the disposing of a DataContext?

删除回忆录丶 提交于 2020-01-01 05:12:45
问题 I have a web service that is quite heavy on database access. It works fine in test, but as soon as I put it in production and ramp up the load it starts churning out errors that are raised when something calls a method in the DataContext. The error is normally one of these: Object reference not set to an instance of an object Cannot access a disposed object. Object name: 'DataContext accessed after Dispose.'. but not always. Any single web service requests can result as many as 10 or 15

WPF data context for design time and run time

假如想象 提交于 2020-01-01 00:46:35
问题 I'm learning WPF, MVVM Light and the ViewModelLocator pattern and running into difficulties with my main window's data context. public class ViewModelLocator { public ViewModelLocator() { var mainModel = new MainModel(); Main = new MainViewModel(mainModel); } public MainViewModel Main { get; private set; } public static ViewModelLocator Instance { get { return Application.Current.Resources["Locator"] as ViewModelLocator; } } } and in my app.xaml: <Application.Resources> <viewModels

Updating error using (ling to sql)

自闭症网瘾萝莉.ら 提交于 2019-12-31 05:38:07
问题 I have two tables, binded by foreign key CarrierID: Carrier[CarrierID,CarrierName] CarrierID = 1, CarrierName = DHL CarrierID = 2, CarrierName = Fedex ... Vendor[VendorID, VendorName, CarrierID] VendorID = 1, VendorName =D-link , CarrierID=1 VendorID = 2, VendorName = Netbes , CarrierID= 2 When i try to update the carriername in vendorview. Im getting this error "ForeignKeyReferenceAlreadyHasValueException" I have class called editvendor public static void editvendor(Vendor vendor) { using

Linq to sql add/update in different methods with different datacontexts

 ̄綄美尐妖づ 提交于 2019-12-30 07:29:27
问题 I have to methods, Add() and Update() which both create a datacontext and returns the object created/updated. In my unit test I call first Add(), do some stuff and then call Update(). The problem is that Update() fails with the exception: System.Data.Linq.DuplicateKeyException: Cannot add an entity with a key that is already in use.. I understand the issue but want to know what to do about it? I've read a bit about how to handle multiple datacontext objects and from what I've heard this way

How to get the TSQL Query from LINQ DataContext.SubmitChanges()

旧时模样 提交于 2019-12-29 03:31:10
问题 I'm using Linq to SQL. I have a DataContext against which I am .SubmitChanges()'ing. There is an error inserting the identity field, and I'd like to see the query it's using to insert this identity field. I don't see the query itself within the quickwatch; where can I find it from within the debugger? 回答1: There is actually a very simple answer to your question Just paste this in your watch window ((System.Data.Objects.ObjectQuery)myLinqQueryVar).ToTraceString() 回答2: Lots of people have been

in Silverlight DataGrid, CheckBox's DataContext sometimes null when Checked/Unchecked

六眼飞鱼酱① 提交于 2019-12-25 18:19:24
问题 I have a DataGrid. One of the columns is a template with a CheckBox in it. When the Checked or Unchecked events trigger, (it happens with both) the CheckBox's DataContext is sometimes null, which causes my code to error. It seems to be null most often if the mouse is moving while you press and release the button quickly (it's intermittent). I listened for changes to the DataContext of the CheckBox by making views:ListenCheckBox (extends CheckBox) and attaching a binding, and it's never set to

Is it possible to access the DataContext of the current page of the frame? How?

北慕城南 提交于 2019-12-25 09:15:06
问题 In wpf, is it possible to access the DataContext of the current page of the frame? If YES, how? If NO, what should I use as replacement for frame so that I can access its DataContext? If something is not clear, please tell me. Update: For Clarification I have a Frame in MainWindow.xaml . I want to access the DataContext of the current page displayed in the Frame . Let's just say I want to display a string property named title of the ViewModel of the current page. (Let's assume that each page'

Linq to sql submit changes () or .Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, “entity to update”)

▼魔方 西西 提交于 2019-12-25 08:18:03
问题 Hello guys as you can see on my Title, I am wondering what is more safe and more stable to use when we are talkin about Linq to SQL , SubmitChanges() method or .Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, "entity to update"), because obliviosly we need to use them everytime we are making changes on database table, thats true? Because in case we are not using them, we will never had updated database model in our IDE (for example visual studio). I just started working with linq

System.InvalidOperationException: An entity can only be attached as modified

孤者浪人 提交于 2019-12-25 05:23:15
问题 am trying to update table called "Hero" , am using DataContext , here is how the codes looks like:- //linq to sql table (automatic generated) [global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Hero")] public partial class Hero : INotifyPropertyChanging, INotifyPropertyChanged { //fields methods etc.. } and there is my own partial class Hero ... public partial class Hero : IHero { //my fields and methods etc... public void Save() { using(GameDBDataContext db = new GameDBDataContext())

Erratic LINQ to SQL Error: “operation cannot be performed during a call to SubmitChanges.”

纵饮孤独 提交于 2019-12-25 04:42:36
问题 Okay, so I'm getting this error from the lines: System.Data.Linq.DataContext.CheckNotInSubmitChanges() +42 System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode) +54 What I'm doing is tracking an application's state and logging each request. The app renders output in Json, Xml and Html. The thing is the error is erratic. It only happens every few requests. The error started happening when I started doing Ajax requests. I've been able to determine that the error occurs more