datacontext

Inconsistent accessibility problem

I am following Rob Conery MVC Storefront tutorial series and I get an Inconsistent accessibility error from the following constructor public SqlCatalogRepository(DB dataContext) : public class SqlCatalogRepository : ICatalogRepository { DB db; public SqlCatalogRepository() { db = new DB(); //turn off change ...

Linq replace field for a subquery

Hi, I have a database containing users and roles. The table Users has a reference to the table roles as each user is bind to a role (one and only one). When I use linq to retrieve the users, the field "role" shows in a datagrid as an integer (which is the primary key of the table Roles). However, I'd like to replace the field Role of the...

Can I reassign from code an object declared as a resource in xaml?

I have a class for my data, MyData, and I'm accessing it in my gui by data binding. I decided to set the DataContext of the main panel in my window to an instance of this object so I could bind my various controls to it's members. So I could easily reference it in my xaml, I created an instance of MyData in Window.Resources like so: <lo...

.NET LINQ-to-SQL asynchronous commit

Hey, i am considering - in order the get a high performance application - to keep a single DataContext in the cache to perform the selects and updates to... In order the keep the responsetimes low, i'd like to create an asynchronous update like the one i scribbled below: public void AsyncInsert() { DataContext dc = new DataContext()...

LINQ to SQL DataContext and Connection Problems

I am using LINQ to SQL for my website to access two databases. The first database is the website (which i'll call WEBSITE) data, the second is a history of transactions (which i'll call WEBSITE_HISOTRY). When I added a table from the WEBSITE_HISOTRY to my datacontext not so long ago i recieved some sort of alert that I clicked OK on (pro...

WPF: ItemsControl and DataContext

I have a main window with a single user control in it, called SuperMode. SuperMode consists of a collection of people and each person in this collection has their own collection of tasks. Sounds simple, right? From file SuperMode.xaml: <UserControl x:Class="Prototype.SuperMode" xmlns="http://schemas.microsoft.com/winfx/2006/xa...

WPF datacontext parent / child usercontrols

I have a WPF application that is made up of a window containing a usercontrol which, in turn, contains another child usercontrol. I have a dependencyProperty for a SelectedName in my second usercontrol's viewmodel. I want the parent control to be able to either access this property and display the SelectedName in a textblock in the par...

Set DataContext of a textbox to the current class in silverlight

Hi, i have a textbox in a UserControl, i created a property in the UserControl, i want to bind the textbox text property to the property created in the usercontrol. The problem is that i dont know how to especify the datacontext to the current class in XAML. Any idea?? thanks ...

LINQ to SQL Classes & Datacontext are not created

Afternoon all This is driving me nuts. For no apparent reason (of course there must be one), my web project will no longer generate LINQ to SQL classes/data contexts!!! I am going about the usual routine of right clicking the project, adding new item, selected LINQ to SQL classes, then dragging over a table from Server Explorer, savin...

In LINQ-SQL, wrap the DataContext is an using statement - pros cons

Can someone pitch in their opinion about pros/cons between wrapping the DataContext in an using statement or not in LINQ-SQL in terms of factors as performance, memory usage, ease of coding, right thing to do etc. Update: In one particular application, I experienced that, without wrapping the DataContext in using block, the amount of me...

Why only some child elements will have their properties defined by their parents

<Window x:Class="tests.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" Background="Red" Foreground="Cyan"> <StackPanel VerticalAlignment="Center"> <Button>123</Button> ...

Use DataContext as CommandParameter in WPF

I want to pass the current DataContext (which is an instance of a ViewModel) as a CommandParameter on a WPF Button. What would be the syntax I should use? <Button x:Name="btnMain" Command="infra:ApplicationCommands.MyCommand" CommandParameter="{Binding ???}" /> ...

Insert another entity in partial insert,update method of an entity

I use LinqDataSource in my web pages and I want to handle Business rules in Changed event of properties and also OnValidate method of an entity. I can delete other entities in partial delete also, I can upload other entities in partial Insert and Update methos but I can't Insert entites in partial update or delete methods. Example : I ha...

When does IQueryable execute the query?

Hi, Ive got the following code which I hacked together from website examples. It works nicely but I dont really understand how it works... public static Func<EuvaTransientDataContext, string, string, int, IQueryable<SecurityAudit>> MatchedIPAddressesAuditRecords = CompiledQuery.Compile((EuvaTransientDataContext db, string us...

How do I correctly dispose a Linq to SQL DataContext in a Repository?

In a Rob Conery-style ASP.NET MVC application, you typically have a repository: public class CustomerRepository { DataContext dc = new DataContext(); public IQueryable<Customer> AllCustomers() { return db.Customers; } public Customer GetCustomer(int customerID) { return db.Customers.FirstOrDefau...

Remove/Stop Storyboard on DataContext change

General context : MVVM application. I have a View called JobView. Its DataContext is a class called Job. Within Job is a property called AuthorizationNeeded. A Border in the view has a style (from a resource dictionary) and that style has a data trigger which starts and stops a storyboard based on the bound property AuthorizationNeed...

Switch `ConnectionStrings` between local and remote with Linq to SQL

First, by Remote I mean a central dedicated SQL Server on our Network. By Local I mean a local SQL Express install. My situation is in house only. No cloud services, external sites, etc. My app allows the user to work disconnected but in order to minimize traffic and a few other issues as well I would like to allow them to connect st...

Should I create multiple LINQ to SQL Classes Contexts in my projects.

This is a design question, I noticed that by time by LINQ-to-SQL Context gets crowded with all the tables from the database, so today I wanted to create a new context for the new tables I added recently. The tables makes up a unit of logic by themselves and they are separated from other tables logically, except for 2 tables. I am plannin...

Asp.Net Random Error

At random times, twice in the past two weeks, the we application will start to error and not work until I recycle the app pool in IIS. The specific error and stacktrace are: System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.InvalidCastException: Unable to cast object of typ...

Linq-to-sql Compiled Query returns object NOT belonging to submitted DataContext ?

Compiled query: public static class Machines { public static readonly Func<OperationalDataContext, short, Machine> QueryMachineById = CompiledQuery.Compile((OperationalDataContext db, short machineID) => db.Machines.Where(m => m.MachineID == machineID).SingleOrDefault() ); public s...