datacontext

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

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

linq to sql datacontext for a web application

Hello, I'm trying to use linq to sql for my project (very short deadline), and I'm kind of in a bind. I don't know the best way to have a data context handy per request thread. I want something like a singleton class from which all my repository classes can access the current data context. However, singleton class is static and is ...

attaching linq to sql datacontext to httpcontext in business layer

Hello all, I need my linq to sql datacontext to be available across my business/data layer for all my repository objects to access. However since this is a web app, I want to create and destroy it per request. I'm wondering if having a singleton class that can lazily create and attach the datacontext to current HttpContext would work....

Which layer should create DataContext?

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

DataContext, DataBinding and Element Binding in Silverlight

I'm having one hell of a time trying to get my databinding to work correctly. I have reason to believe that what I'm trying to accomplish can't be done, but we'll see what answers I get. I've got a UserControl. This UserControl contains nothing more than a button. Now within the code behind, I've got a property name IsBookmarked. When I...

WPF Binding Syntax Question

I've seen this syntax show up, and have tried to google for it's definition to no avail; what does it mean when a dp is bound this way? <Grid> <ContentControl Content="{Binding}"/> </Grid> I was under the assumption that you have to bind to some property on the DataContext, or another element, but this appears to bind to nothing. ...

easiest way to renew Datacontext binding in WPF

What is the fastest way to update my DataContext binding to my WPF usercontrol so that it shows changes in the object it is bound to in the view? ...

ASP.NET Thread Safety in aspx.cs code behind file

I am thinking of adding a DataContext as a member variable to my aspx.cs code-behind class for executing LinqToSql queries. Is this thread safe? I am not sure if a new instance of this code-behind class is created for each HTTP request, or if the instance is shared amongst all request threads? My fear is that I will get 10 simultaneo...

Using ASP.NET MVC, Linq To SQL, and StructureMap causing DataContext to cache data

I'll start by telling my project setup: ASP.NET MVC 1.0 StructureMap 2.6.1 VB I've created a bootstrapper class shown here: Imports StructureMap Imports DCS.Data Imports DCS.Services Public Class BootStrapper Public Shared Sub ConfigureStructureMap() ObjectFactory.Initialize(AddressOf StructureMapRegistry) End Su...

Binding from DataContext in Blend 3

i'm trying to build a simple application, that changes images based on Selected item in ListBox. <Grid> <Grid> <Image /> </Grid> <ListBox /> </Grid> The XAML looks similar to this. So i set DataContext of the "inside" Grid to the ListBox's SelectedItem property. The problem is that when i try to DataBind Image source p...

Testing the context in asp.net mvc

I got pretty experienced with testing controllers, my question here is though, aren't we supposed to test the data context as well, and how ? I mean, there are a lot of relationships and constraints coming from the DB that simply testing controllers does not cover. On the other hand, testing against the DB is not considered a good prac...

DataContext not visible when choosing data source for LinqDataSource

I have a page on which I've thrown a LinqDataSource and a GridView. I've created a DataContext LINQ-to-SQL class called dcResidents.dbml. When I attempt to configure the LinqDataSource to utilize the dcResidents data context - it doesn't appear in the list of options...though under class view (tab in VS) it does appear. I do have several...

Is there anyway to stop automatic DataContext inheritance in Silverlight?

Is there anyway to stop automatic DataContext inheritance in Silverlight? I Set my DataContext on my parent UserControl in code. As a result all the xaml bindings inside the UserControl try to bind to the new DataConext they get (through the automatic DataContext Inheritance). The DataContext's for the children elements (actually they ...

Validation (with custom ErrorTemplate) for a DataTemplate

I can't figure this guy out / in desperate need of assistance. I have an ItemsControl and a DataTemplate as the ItemTemplate i.e. <DataTemplate> <StackPanel> <TextBox Text={Binding Prop1}/> <TextBox Text={Binding Prop2}/> </StackPanel> </DataTemplate> I have seen plenty of examples for applying validation to th...

Cannot add table to context - LINQ-To-SQL

Hey, I'd be happy to give you more info if you need, just ask for it. I have in my database a table of articles, a table of tags and a link table. The article table has values like Id, Subject etc etc, the tags only have Id and Tag. The link has TagId and ArticleId. The problem is that when I drag drop the link-table nothing happens! ...

LINQ 2 SQL: Partial Classes

I need to set the ConnectionString for my DataContext's based on an AppSetting. I am trying to do this by creating a Partial Class for each DataContext. The below is what I have so far and I am wondering if I am overlooking something? Specifically, am I dealing with my DataContext's correctly(disposing, staleness, etc)? Doing it th...

LINQ Datacontext Disposal Issues

I am getting a Cannot access object: DataContext after it's been disposed in the below DAL method. I thought that I would be okay calling dispose there. result is an IEnumurable and I thought it was IQueryable that caused these kinds of problems. What am I doing wrong? How SHOULD I be disposing of my DataContext. Is there somethin...

Can I stop the dbml designer from adding a connection string to the dbml file?

We have a custom function AppSettings.GetConnectionString() which is always called to determine the connection string that should be used. How this function works is unimportant to the discussion. It suffices to say that it returns a connection string and I have to use it. I want my LINQ to SQL DataContext to use this so I removed all...

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 property "DisplayText" <TextBlock Text="{Binding Path=DisplayText}"/> From here, if the Dat...

Inheriting LINQ-to-SQL data context from base controller

My base controller class, BaseController, is inherited by public-facing controllers to access a shared data context between requests with LINQ-to-SQL. Am I accessing my data context in an efficient and safe way by storing it in HttpContext.Current.Items for each HTTP request? DataContextHelper class internal static class DataContext...