datacontext

Scoped DataContext intermittently raises ExecuteReader error

Our application follows the approach of maintaining a DataContext per Thread/HttpContext, using the DataContextFactory class outlined by Rick Strahl on his blog, including the amendment to the Key mentioned by Richard (use of type.AssemblyQualifiedName). The solution appeared sound (although in most cases a different approach may be bet...

Passing DataContext to User Control in WPF

I have a usercontrol that acts as a container for a ContentControl. The user control container has a listview control that I want to use to update controls in a dynamically added user control assigned to the ContentControl. IOW, as I scroll through the listview control, the textbox's in the UC assigned to the ContentControl should update...

Is the HttpContext.Current disposed even if an exception is thrown?

The reason I ask is because the HttpContext.Current.Items collection seems like it would be a good place to put IDisposable objects such as a DataContext so that a Repository might access it transparently without having to to inject any dependencies related to a specific ORM technology into the Repository. This would also allow the repos...

How do you clear changes in LinqToSql?

I have a combobox in my WPF app that is databound to my list of objects in my View Model. When the user makes changes to the selected object and then selects another item before saving, I need to clear the changes made. I thought I could use dataContext.GetChangeSet().Updates.Clear() but for some reason the collection is read-only. I'...

How do you setup custom Insert/Update/Delete methods to inherited sub-clasess in LinqToSql?

I have created a bass class in LinqToSql which has 2 sub-classes. I need to assign a different stored procedure to each of the sub-classes custom update methods. Doing this is fine, but I get an error of "Invalid object name 'xxx'". e.g. DataClasses1DataContext dc = new DataClasses1DataContext(); Class2 c2 = new Class2() { ID = 1, N...

Linq to SQL Data context doesnt commit if multiple inserts are called on table with auto increment

I am having an issue when trying to submit two inserts at once. The table has a auto increment primary key. The comment objects set up dont have there ID value set so that the database can assign this. My code works for single inserts if i submit straight away but if i try and do multiple InsertOnSubmit commands then it seems to do noth...

LINQ to SQL: using string filename to create a DataContext at runtime

Hi, With FileInfo I can find the file name of a DataContext .dbml file. Provided I declare: Dim DataModel = New AttributeMappingSource().GetModel(GetType(NorthwindDataContext)) With System.Data.LINQ.Mapping I can find the name of all Tables and furthermore their Columns and relationships. All this thanks to the excellent post from ...

What defines the bindings update order in WPF?

Hi, I have a piece of WPF/C# code that uses several Bindings: A combobox is used to select an Account The itemssource property of a second combobox is bound to the selected Account. This second combobox is used to select a Contact The itemssource property of a grid is bound to the selected Account. This grid contains the selected Acco...

Mimicking SQL Insert Trigger with LINQ-to-SQL

Using LINQ-to-SQL, I would like to automatically create child records when inserting the parent entity. Basically, mimicking how an SQL Insert trigger would work, but in-code so that some additional processing can be done. The parent has an association to the child, but it seems that I cannot simply add new child records during the Dat...

binding a combobox to different DataContext

Hello, The combobox items are taken from one table, one field on which binding is made. After I saved in the database the selected item in another table, I want that the selected item to be the one which was saved. But the selected item is lost. So, my question is: can I bind the combobox to two DataContexts or maybe another solution ?....

StackPanel not updating

Hello, I am having an issue with a directly bound ObservableCollection not updating a StackPanel when new items are added. Any initial items show up correctly. Only items that are added later on fail to display. XAML: <ItemsControl x:Name="ImageTable" ItemsSource="{Binding Path=SystemObjectViewItems, Converter={StaticResource UIElementW...

How to publish ASP.NET MVC site using datacontext to external SQL Server?

I am playing with MVC and I made a simple site. I have an seperate machine running SQL Server Express and on it I have a simple table called "Log". The table has ID, Timestamp, and Message fields. I added the database to my "Data Connections" on my "Server Explorer" section. In my MVC website I created a new LINQ to SQL class and dragge...

Escape from DataContext

I have a window that get its data from another class that is passed as DataContext. But I now also want to do data binding within the window. The window looks as follows: <Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xa...

Null Reference Exception In LINQ to SQL DataContext

I have a Null Reference Exception Caused by this code: var recentOrderers = (from p in db.CMS where p.ODR_DATE > DateTime.Today - new TimeSpan(60, 0, 0, 0) select p.SOLDNUM).Distinct(); result = (from p in db.CMS where p.ORDER_ST2 == "SH" && p.ODR_DATE > DateTime.Today - new TimeSp...

WPF DataContext vs ItemsSource Performance

Hi! Suppose we have an ItemsControl, which is bounded to a source. Is there any performance difference between ItemsControl.DataContext = resultSet; and ItemsControl.ItemsSource = resultSet; (In both cases correctly binded in XAML) ...

Executing Method Against DataContext Returning Inserted ID

Is there any way to use DataContext to execute some explicit SQL and return the auto-increment primary key value of the inserted row without using ExecuteMethodCall? All I want to do is insert some data into a table and get back the newly created primary key but without using LINQ (I use explicit SQL in my queries, just using LINQ to mo...

WPF DataContext for Child/Detail UserControl/View

I am new to C# and WPF, so please bear with me.. This isn't exactly a Master/Detail scenario, and could be why I am having problems, but generally, I am trying to figure out how to relate two sets of data that are not quite master/detail. To keep it simple, let's say I have two view/viewmodels for 1) Person ID, FirstName, LastName 2...

Any way to improve Linq-To-SQL performance?

Please offer advice if you can... I've based my project on Linq-To-SQL, and the (almost) finished application has very poor performance. I've fired up the SQL Profiler many times to optimize the queries with LoadOptions to reduce the number of round-trips to the database server, but at the end of the day, my conundurum is weaved into th...

How do I get the ColumnAttributes from a Linq.Table<TEntity>?

I'm trying to return attributes of columns from my DataContext. How can I pull out the ColumnAttribute meta data? public class MyDataContext : DataContext { public Table<User> User; public MyDataContext(string connection) : base(connection) { } } [Table(Name = "User")] public class User { [Column(IsPrimaryKey = true)] ...

How to handle nested datacontext in the BL?

public class TestBL { public static void AddFolder(string folderName) { using (var ts = new TransactionScope()) { using (var dc = new TestDataContext()) { var folder = new Folder { FolderName = folderName }; dc.Folders.InsertOnSubmit(folder); ...