datacontext

Linq2SQL: Why doesn't datacontext update database

This is my first go at LINQ to SQL. I create my dbml in the designer using a SQL Server Express database. I create a stored procedure called StoredProcedure1, which I also dragged into the dbml. Then I wrote up some code to test if I could update some of the fields. The problem is that no updates occur to the database, but I see the ...

What is the best LINQ-to-SQL strategy for disposing of DataContext within methods?

I understand that it is good practice to use a using block when getting data from the LINQ-to-SQL classes as shown below. However, when I do this, I can only access the shallow properties of orders (e.g. Order.OrderId) but not the deeper properties (e.g. Customer.CustomerName) since they seem to be disposed of at this point. I can take...

UNITY: passing in a new datacontext each time?

Hi there, I am trying to use unity to automatically inject a datacontext on my repository using a new instance each time.., my idea is the ensure that each time a new datacontext is injected Currently its failing on creating the repository, i think it can't resolve MyDataContext Before creating a constructor on "the repository" (see b...

Unity: Using same datacontext in application_BeginRequest?

Hi there, Previously i managed to setup my unity to provide a new DataContext each time to my Repository project. It works great. But for example, I am in a WCF method which opens up 2 services which in turn opens up 2 repositories (repository pattern).. i was hoping to be able to reuse the same datacontext within the same wcf method....

In Memory DataContext

Is it possible to get a LINQ to SQL DataContext to run completely in-memory? Without it touching the database? I am doing some very rapid prototyping, and want to minimize the surface area for major changes since the UI is changing so fast. However, the data model already exists. Data access is handled through the use of I[Model]Reposi...

What is purpose of UpdateObject for Linq to REST?

When one is using ADO.NET Data Services and consuming it via the Linq to REST (formerly Project Astoria), it doesn't seem to be as intuitive as it could be. Namely, with normal Linq to SQL, the DataContext monitors objects and tracks changes, so a simple SubmitChanges() call will actually submit all my changes. But with Linq to REST, I...

LINQ To SQL exception with Attach(): Cannot add an entity with a key that is alredy in use

Consider this typical disconnected scenario: load a Customer object from SQL Server using LINQ To SQL user edits the entity, and the presentation tier sends back the entity modified. the data layer, using L2S, must send the changes to SQL Server Consider this LINQ To SQL query whose intention is to take a Customer entity. Cust cust...

Model - Partial class and Datacontext class are not communicating.

Hello, I've created a one table contact DB, which has only 3 columns (Id, Name, and Phone). I've then created the ContactsDataContext using my table Contacts in the model folder. Finally, I create a partial class still in the model folder (public partial class Contact). now when I write this public partial class Contact { public...

Silverlight behavior based on update of view model property

Hi, I'd like to have a Silverlight behavior that is triggered by a change to a property in the view model for my page. I can't figure out how to do this, however. So, I have a very simple view model: public class MyViewModel : INotifyPropertyChanged { private bool changingProperty; public bool ChangingProperty { ge...

Linq to Sql DataContext life cycle in a WCF service

Hi, I have a service exposed via WCF. The service exposes several methods that talk to the database through a Linq to SQL datacontext. The datacontext is bound to the CallContext. All of this is working as it should but I can't figure out the proper place to dispose the Linq to SQL datacontext. Please help. ...

Multi-threading with Linq to SQL

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

Can 'Not putting my DB under the 'App_Data' affect the way Linq2Sql works?

Hello, I'm experiencing a problem while working with all my projects. I don't get Intellisense with Linq2Sql and, when I write partial classes in the model folder, properties created by the Linq2Sql designer are not recognized by the partial classes. So, I'm trying to rule out all the possible sources of the problem. I have 2 cases: ...

WPF Show data from multiple DataContexts in ToolTip of ItemsControl

Hi, I am trying to display a tooltip for an item generated by an ItemsControl that needs to pull data from conceptually unrelated sources. For example, say I have an Item class as follows: public class Item { public string ItemDescription { get; set; } public string ItemName { get; set; } } I can display the Item within an It...

LINQ TO SQL error: An attempt has been made to Attach or Add an entity that is not new...

"An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This is not supported." I have scene a lot of solutions dealing with the Attach() method but I'm just trying to add in a new record. Not sure what is going on. Here is my code, It is failing on the star'd line.: ...

How do I disable LINQ to Sql transactions?

I want to make additions to a database, in this case massive amounts of information, with no transactions on my LINQ To SQL model. Does anyone know how to turn off LINQ To SQL transactions on a datacontext or on the submit changes operation? ...

Multiple Database Connection using LinqToSql DataContext

hi sir/madam, i realized that when i'm trying to create 2 instance of LinqToSql DataContext as below and SQL server using the same SPID for them. my question is with following code, would LinQToSql established 2 database connections or 1? how to establish 2 different database connection using LinqToSql DataContext? LinqToSqlDataConte...

Time Stamp in DBML is solving concurrency issues...why?

We use LINQ in our ASP .NET application to run database queries and commands. We have been having concurrency issues on updates to tables in which we update the value of a Date field. More specifically, if two users click a button at the exact same time and the code attempts to update a Date field in the database then the built-in optim...

How to bind to a data-context outside of WPF toolkit datagrid

Hi, OK So I have a combo box which selects an administrator from a list of administrators: <ComboBox x:Name="adminCombo" ItemsSource="{Binding AdminsList}" DisplayMemberPath="Name" SelectedValue="{Binding Administrator}" SelectedValuePath="Name"/> and below this I have a WPF Toolkit DataGrid. E...

Linq to Sql not submitting changes to database file in console app

I have an issue with my Linq to SQL Data Context no submitting in my console application. The following code is all that there is in the main() method. BlogRollerDataContext bdc = new BlogRollerDataContext(); bdc.Urls.InsertOnSubmit(new Url() { Approved = false, UrlTo = "http://www.google.com/", UrlFrom =...

WPF - cloning objects for an XPS document

Here's the bottom line: I'm trying to avoid using RDLC/SSRS and instead create XPS files from my XAML. I've combined pieces of code from various articles here and I am (1) cloning the XAML objects I need from my page and (2) passing those to a new page in an XPS object This process seems to work just fine with non data-bound objects th...