datacontext

DataContext's Connection string help

I have the following connection string: "Data Source=localhost\\SQLEXPRESS;", it complains that '' is an invalid username. I can't quite remember the user name or password commands, nor can i remember if there's anything else i'm missing. Can someone help? ...

Linq2Sql: re-Attaching entity to datacontext but not original datacontext problem

Hi there, can anyone help? I have an issue with linq2sql and trying to Attach (update) an entity class through a datacontext, it complains its not the original context, this is true (see code below) ... I thought it was best practices to open the datacontext and close it when not needed? I basically have my app calling a service layer...

Binding to the selected TabItem content

I have a Window with two controls: control1 is a control that has a bunch of buttons that execute RoutedCommands; the second control is a TabControl that is bound to a list of documents. The TabControl ContentTemplate is a user control, control2, that has a ListView. I would like to bind the DataContext of control1 to the ListView of con...

Unit Testing, Linq to SQL and working around the Data Context

Hi guys I have been looking at the following and it would appear that there are great benefits to be gained by using compiled queries... http://blogs.msdn.com/ricom/archive/2008/01/14/performance-quiz-13-linq-to-sql-compiled-query-cost-solution.aspx My problem is that I want to unit test my queries, but compiled queries need a concre...

C# add a Table<T> into an existing DataContext Instance

Hello, Guys Is it possible that I can add Table<T> dynamiclly to an exisitng DataContext Insance in LinqToSQL? Here is my case: I have several classsed which are using [Test] attribute to declared as Table, I want to allow user to create the corresponding SQL Server tables during run-time. I understand that If I inherit the DataC...

Can I call a Method in one DataContext from another?

I have the below LINQ Query that I would like to suppliment with the Nurse Names. Unfortunately these are stored in a seperate DB and thus a seperate DataContext. How would I go about calling a method in my aspnetdbcontext from this query, which uses cmodatacontext? This is the method in aspnetdb to get a nurse's name: internal s...

LINQtoSQL Not saving to database,but changes show in app.

Hey all, I have a linq app using C# express2008 and sqlserver express 2005 (mdf file connection) I followed the regular dml generation and vanilla datacontext. However i created a repository class to manage the Linq stuff. In using the functions, selecting data works fine, updating data works in the app.But when i check the data in the ...

Help me to understand MY`Using` and `DataContext`

Can someone please explain the below to me. First is how I call the method and the second bit is the LINQ Method. My curiousity stems from the fact that I get a context error if I un-comment the using portion. Why? I apparently do not fully understand using and context's. And I would like to better understand this. Guid workerID =...

WPF (MVVM): Wiring up viewModel to view in code-behind of Window?

Hi there, I have been getting my feet wet with MVVM pattern for WPF and everything is working as it should.. But i am wiring up the viewmodel to my view datacontext from my codebehind of my window. Sure enough the point of MVVM is to get rid of code behind in windows... which it does great, so i am left with 2 simple lines to wire up...

Linq to SQL - Retain DataContext across post-backs?

I read Rick Strahl's post about DataContext lifetime management, and some of the other related questions on Stackoverflow. If they contained an answer to my question, I must have missed it. I generally follow the atomic approach and instantiate a DataContext for a unit of work when it is needed, and dispose it afterwards. This worked w...

WPF Databinding and Styles with MVVM

I have a problem with databinding on a style in WPF. The basic setup looks like this: <Style x:Key="{x:Type eo:Player}" TargetType="{x:Type eo:Player}"> <Style.Triggers> <DataTrigger Binding="{Binding Team}" Value="A"> <Setter Property="Template" Value="{StaticResource TeamATemplate}"></Setter> </DataTrigger> ...

Filter every call made by a DataContext when using LinQ Entities

I'm using logical delete in my system and would like to have every call made to the database filtered automatically. Let say that I'm loading data from the database in the following way : product.Regions How could I filter every request made since Regions is an EntitySet<Region> and not a custom method thus not allowing me to add is...

LinqPad, using multiple datacontexts

I am often comparing data in tables in different databases. These databases do NOT have the same schema. In TSQL, I can can reference them with the DB>user>table structure (DB1.dbo.Stores, DB2.dbo.OtherPlaces) to pull the data for comparison. I like the idea of LinqPad quite a bit, but I just can't seem to easily pull data from two d...

Set Window.DataContext to a declared property in the code-behind?

I want to achieve something like the following (Notice the DataContext property of the Window element): <Window x:Class="Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" DataContext="{Binding MyDataContext}"/> Class Window1 Public ReadOnly...

Fetch Single Item Using DataContext

I'm doing the following: public MyItem FetchSingleItem(int id) { string query = "SELECT Something FROM Somewhere WHERE MyField = {0}"; IEnumerable<MyItem> collection = this.ExecuteQuery<MyItem>(query, id); List<MyItem> list = collection.ToList<MyItem>(); return list.Last<MyItem>(); } It's not very elegant really and I was hopi...

Setting DataContext for the root element in XAML without the property element syntax

I was wondering if it's possible to write something like this: <Window ... xmlns definitions ... DataContext=<!--Create an instance here--> ></Window> Instead of this: <Window ... xmlns definitions ... > <Window.DataContext> <local:CustomViewModel /> </Window.DataContext> </Window> I don't need workaroun...

linqtosql 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 cannot delete a record: public static bool DeleteProject(Project project) { invoicesLINQDataContext context = new invoicesLINQDataContext(); context.Projects.Attach(project, true); context.Projects.DeleteOnSubmit(project); try { context.SubmitChanges(); ...

Linq to Sql - DataContext design issues and considerations in ASP.NET MVC application

I am using "Single data context per atomic operation" approach while using Linq to Sql in an ASP.NET MVC application. So far, I have been using a singleton datacontext, which I learnt has many issues, so I refactored the code to use single datacontext per atomic operation. An example of a controller action is now as follows (refactorin...

What is the best practice for committing changes using a LINQ2SQL datacontext in a Silverlight application using RIA?

I've got a Silverlight app using RIA services and LINQ2SQL and have objects in my Silverlight app. I query all the records in a table (via a LINQ query, using a datacontext) in the Silverlight app and create a user control for each object (record) and put that object into the control because I need the information later. Then later,...

Prefetching data in with Linq-to-SQL, IOC and Repository pattern

Hi, using Linq-to-SQL I'd like to prefetch some data. 1) the common solution is to deal with DataLoadOptions, but in my architecture it won't work because : the options have to be set before the first query I'm using IOC, so I don't directly instanciate the DataContext (I cannot execute code at instanciation) my DataContext is persis...