datacontext

Detect a DB Connection error using Linq?

Is it possible to detect an error in a connection before we get an application "Transport-level error" using Linq? Lets say that I have a SQL server called SQLServer1, and I am running an application that connects to that server using LinQ to get some information. I decide to change the server Name to SQLServer2. The next time my appl...

Why is my DataContext null in only one action?

I have a property on my BaseController called DataContext that holds my LINQ to SQL data context (or fake context for testing). When using a parameterless constructor (in other words, when a request to ASP.NET MVC is made), a new instance of my LINQ to SQL data context is assigned to the property: public class BaseController : Controlle...

"Property 'Path' does not have a value"

Visual Studio WPF editor worked fine all the time. Yesterday, it started complaining about the aforementioned error. I don't recall fiddling with its settings or anything. What's up? I want to fix the editor and not wade through my code adding Path=. everywhere. ...

C# Linq: Can you merge DataContexts?

Say I have one database, and this database has a set of tables that are general to all Clients and some tables that are specific to certain clients. Now what I have in mind is creating a primary DataContext that includes only the tables that are general to all the clients, and then create separate DataContexts that contain only the tabl...

LINQ :: Use static DataContext to prevent Concurrency Problem

Hi i am facing some problems in my project. when i try to update entity it gives me different type of errors. i read from net. these errors are because 1 - I am getting Object of entity class from method which creates DataContext locally and in update method id does not update because here another DataContext is created locally. (eve...

Dependency Properties and Data Context in Silverlight 3

Hello, I am working with Silverlight 3 beta, and am having an issue. I have a page that has a user control that I worte on it. The user control has a dependency property on it. If the user control does not define a data context (hence using the parent's data context), all works well. But if the user control has its own data context, the...

Overwrite DataContext methods in LINQToSQL

Hi, I am new to LINQToSQL. Is there a way to overwrite the "InsertOnSubmit" or "DeleteOnSubmit" methods of the DataContext class for a particular entity? Like for example, I have a database table called Customers that has a boolean field "IsDeleted" which holds true if the user deletes a customer record from UI. If I will call the _myDa...

How to use TypeMock Isolator with Linq to SQL and DataContext

Hi, i am using TypeMock Isolator to fake the tables on my DataContext like this: Isolate.Swap.CallsOn(ctx.GetTable<TTable>()).WithCallsTo(content); I now can fill the "database" with arbitrary data on each test. In order to get meaningful data for the test scenario into the DataContext i usually have to create 3-5 objects. Now, the p...

Different data contexts in a SL3 form

I wrote a custom Silverlight 3 control that uses a class as its data context (MVVM pattern). I want to place this control on another control (form) through XAML. The child control exposes a Dependency Property that when set through XAML, will make it show detailed info. So an example is that the child control shows order details data, ...

In C#, how can I set DataContext on a View from the ViewModel?

I"m trying to wrap my head around MVVM. I understand a lot of it, but I'm having difficulty grasping one aspect: Setting DataContext. I want to show an view with a particular object. The user doesn't get to decide what is visible, so I need to create the view in code. Then, I want to set the DataContext of the view to an object (for b...

How to update a BindingSource based on a modified DataContext

In my application, I extract the Data of a Linq To SQL DataContext into a dictionary for easy use like so: Jobs = dbc.Jobs.ToDictionary(j => j.Id, j => j); Then I bind this dictionary to a BindingSource: bsJob.DataSource = jobManager.Jobs.Values.ToList(); I refresh the DataContext and the Dictionary regularly for when new Jobs are ...

Datacontext and Unit of work

i am a newbie to Object oriented programming. I have spent 8 years as a procedural programmer. Even though Linq to Sql might not be a good choice going forward, it is still a good lightweight ORM. If I want to use LTS as my data access, and I have a MVP Pattern for my UI, than my question is as follows In an MVP Pattern you typically cr...

Quick way to detect if a DataContext table or view exists

Currently, I'm developing an application that depends on (and thus connects to) various databases via LINQ-to-SQL. For one of the databases, the connection string may vary and is thus configurable - however, the schema of this database is identical for all connection strings. Because of the configurable connection string, I want to val...

Datacontext and Nhibernate Session

I am a newbie to Object Oriented Programming. I am working with Windows Application and Model View Presenter Pattern and I want to have the Change tracking available. My question is as follows Do I need the presenter to hold a Nhibernate Session or Linq to Sql Datacontext for my Unit Of Work? Is this the simplest way I can architect a W...

Setting User Control's DataContext from Code-Behind

This should be pretty easy, but it throws VS2008 for a serious loop. I'm trying out WPF with MVVM, and am a total newbie at it although I've been developing for about 15 years, and have a comp. sci. degree. At the current client, I am required to use VB.Net. I have renamed my own variables and removed some distractions in the code b...

Using Linq SubmitChanges without TimeStamp and StoredProcedures the same time

I am using Sql tables without rowversion or timestamp. However, I need to use Linq to update certain values in the table. Since Linq cannot know which values to update, I am using a second DataContext to retrieve the current object from database and use both the database and the actual object as Input for the Attach method like so: Publ...

LinqToSQL - mapping out the DataContext with lots of tables?

I've been working on a project where I have been using LinqToSQL that involved a lot of tables. All of these where mapped in one .dbml file (i.e. only one DataContext). I did this on the pretense that (currently) you cant join across multiple data contexts. For example... DB1DataContext db1 = new DB1DataContext(); DB2DataContext db2 = n...

WPF Databinding: How do I access the "parent" data context?

I have a list (see below) contained in a window. The window's data context has two properties, Items & AllowItemCommand. How do I get the binding for the Hyperlink's Command property needs to resolve against the window's DataContext? <ListView ItemsSource="{Binding Items}"> <ListView.View> <GridView> <GridViewCol...

Binding ItemsSource to a "proxy" collection. How to get DataContext?

We've got a Silverlight application with several listboxes and comboboxes that display data sorted incorrectly, which I need to fix. Most of their ItemSource properties are set through XAML. Their DataContext may not be set directly on the control, and instead were set on a parent. So I can't easily slap an "OrderBy" on the ItemSource or...

Why are my Validation Rules not being run when DataContext is set?

I have the following Loaded event on my Window: void Window_Loaded(object sender, RoutedEventArgs e) { this.DataContext = new MyObject() { MyDateTime = DateTime.Now, MyNotEmptyString = "Not Empty", MyNotUpperCaseString = "not upper case", MyInteger = 20, MyIntegerInRange = 1, MyDouble ...