datacontext

How to implement commanding in silverlight

Simple case: <usercontrol> <Views:UserListView x:Name="settingsTreeView"/> <Button DataContext="{Binding ElementName=settingsTreeView, Path=SelectedItem}" Command="{Binding CreateChildCommand}"/> </usercontrol> The task just is to bind to button a DataContext which implements CreateChildCommand. DataContext is the sel...

Simple LINQ insert record not working

I have an .mdf file which I'm trying to add a record to, using linq in C#. My code is: dbDataContext context = new dbDataContext(); book b = new book(); b.title = "Test Book"; b.isbn = "123789"; context.books.InsertOnSubmit(b); context.SubmitChanges(); When this code runs, the record is not inserted, and I get no error messages. If I ...

Suppressing TransactionScope enlistment of a readonly EF context?

I have a scenario where I need to open multiple datacontexts which point to different databases. I am only writing to one of the databases though and reading from the others ... so technically the transaction should only be against one of the databases. I'd like to avoid having the TransactionScope upgrade into a distributed transaction...

Is it safe to call BeginSaveChanges(null, null) to perform a Fire and Forget Async DataContext call?

I noticed when performing many database transactions using BeginSaveChanges(null, null) the last query is sometimes unsuccessful. Is it because the instance of my DataContext died too quickly for the query to be performed? When I changed my code to use the normal SaveChanges all the queries are successful. Specifically, I'm performing ...

LINQ to SQL - method run for 2nd time does not return data changes that happened since 1st time

I have created a method in my data context that is mapped to a SQL stored procedure. The method is used in an ASP.NET application, and it is called twice in the lifecycle of a page. It returns the same single object in both cases (i.e. same primary key). After the 1st call some data changes are made, so on the 2nd call the stored proce...

Data Context's SubmitChanges method causing a entity reference to be set to null

I know this looks a bit long but i tried to explain the problem as throughly as i could. We are having a very 'exotic' problem with the linq to sql data context class. We have a n-tiered architectured structured like this: We have 3 classes MotherClass, ChildClass, ChildChildrenClass MotherClass looks something like this: public class...

page.DataContext not inherited from parent Frame?

I have a Page page in a Frame frame, with frame.DataContext = "foo". (page.Parent as Frame).DataContext is "foo". ok BindingExpression for page.DataContext is null (also forced with ClearValue). ok page.DataContext is null. but I expected "foo"! Why isn't the DataContext inherited? As far as I understand the Frame sandboxes the conte...

WPF buttons are outside the datacontext and could not be bound

Hello, I have 3 Buttons add,delete,open as RelayCommands in my DocumentViewModel. Below you see how I have bound them. Of course those binding does not work, because the data is set to the ItemsSource of the ListBox and the buttons are outside of that... What I tried then is to set the DataContext at the first StackPanel you see in my ...

Can't access datacontext in multivalueconverter

I have a usercontrol which I need to set a specific DataContext on. The usercontrol uses multivalueconverters. However, the binding in multivalueconverter fails to use the datacontext. It works fine for regular value converters. Anyone know what is going on? To clarify, below code is not similar to my real code, it's just a sample repro...

Is the DataContext class specific to SQL Server?

The MSDN page for the DataContext class says: Represents the main entry point for the LINQ to SQL framework. Yet it looks like the constructors will take any ADO.NET IDBConnection. Am I right in thinking that a DataContext can wrap any ADO.NET connection? Or are there special things that need to be considered when using a connecti...

please help with sqlite exception

hi, I'm getting this error when the program executes mainDb.SubmitChanges(): INSERT INTO projects VALUES (@p0) SELECT CONVERT(Int, SCOPE_IDENTITY()) AS [value] -- @p0: Input String (Size = 0; Prec = 0; Scale = 0) [test2] -- Context: SqlProvider(Sql2008) Model: AttributeMetaModel Build: 3.5.30729.4926 my code has the following files: P...

Misunderstanding databinding fundamentals and DataContexts -- long story

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 f...

What's the Oracle equivalent of System.Data.Linq.DataContext?

I am implementing the IRepository interface against an Oracle database. public interface IDinnerRepository { IQueryable<Dinner> FindAllDinners(); IQueryable<Dinner> FindByLocation(float latitude, float longitude); IQueryable<Dinner> FindUpcomingDinners(); Dinner GetDinner(int id); void Add(Dinner dinner...

WPF/C# Forwarding events and DataProvider values within a UserControl

I have a UserControl which contains 4 ToggleButtons and I'd like to trigger a custom event that an interested object can listen for which provides a status, based on the ToggleButton Checked values and also value(s) from the DataContext object. Getting the ToggleButton checked values and deriving a status is simple enough, however I can...

DataContextChanged of a Tab in a TabControl is raised too early

I have a TabControl binding to some items. Underneath it is a Button where I can add items dynamically. On adding an item, the new item should become the active Tab (works fine with TabControl.SelectedItem): <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xml...

LINQ - how to make change tracking work when entity passed to another class as property

Here's the scenario: I have an ASP.NET user control that runs a LINQ query, stores the results in a generic List, then dynamically loads another user control (into a Placeholder) and passes one of the objects from the List to the control through a property on the control. The child control displays data from the object and allows the u...

DataContext compiled query problem with .NET 4

My project (UI layer is asp.mvc) was developed using .NET 3.5. After upgrading to .NET 4.0 I have got problem with compiled queries: [ArgumentException: Query was compiled for a different mapping source than the one associated with the specified DataContext.] System.Data.Linq.CompiledQuery.ExecuteQuery(DataContext context, Object[] ...

Unity with a Linq to Sql DataContext. RegisterType or RegisterInstance

Here's the basic setup. On an ASP.Net website, there are a few pages that display reports from data that comes from a database. All the data comes via stored procedures that is accessed usign Linq to Sql. These pages may have some very high traffic at different times. We're using ASP.Net with the MVP pattern, and Unity for IoC (although ...

How can I use DataContext class to establish a connection to Oracle Database?

Is it possible to use the DataContext class to connect to an Oracle DB? I am reading some examples on MSDN I need an example where the context is used to connect to Oracle. ...

Opinion on reuse of db context in Linq

I have a class that uses linq to access the database. Some methods call others. For example: class UserManager { public User[] getList() { using(var db = new MyContext()) { return db.Users.Where(item => item.Active == false); } } public User[] addUser(string name) { using(var db...